/[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.9 - (show annotations) (download)
Mon Jul 28 20:54:14 2014 UTC (10 years, 11 months ago) by gforget
Branch: MAIN
Changes since 1.8: +16 -12 lines
- fix windows PC compatibility (contributed by D.Spiegel).

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 (latex x 2 then dvipdf)
11 % 6 remove temporary files (incl. *fig*.ps)
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 if isempty(myFile);
18 %if no file name, then do nothing
19 return;
20 end;
21 if iscell(myFile);
22 %extecute alternative command (myFile{1}) passing rest as arguments
23 eval([myFile{1} '(myFile{2:end});']);
24 return;
25 end;
26
27
28 myText=[]; myLev=[]; myFig=[]; myRdm=[];
29 if myStep<4; myText=varargin{1}; end;
30 if myStep==0; myRdm=varargin{2};
31 elseif myStep==1; myLev=varargin{2};
32 elseif myStep==2; myFig=varargin{2};
33 end;
34
35 %create file starting with write2tex.header
36 if myStep==0;
37 test0=dir(myFile);
38 if ~isempty(test0);
39 test0=input(['you are about to overwrite ' myFile ' !!! \n type 1 to proceed, 0 to stop \n']);
40 else;
41 test0=1;
42 end;
43 if ~test0;
44 return;
45 else;
46 fid=fopen(myFile,'w');
47
48 fprintf(fid,'\\documentclass[12pt]{beamer}\n');
49 fprintf(fid,'%%a nice series of examples for the beamer class:\n');
50 fprintf(fid,'%%http://www.informatik.uni-freiburg.de/~frank/ENG/beamer/example/beamer-class-example-en-5.html\n');
51 fprintf(fid,'\\usepackage{multicol}\n');
52
53 fprintf(fid,'\n');
54 fprintf(fid,'\\newcommand\\Fontvi{\\fontsize{6}{7.2}\\selectfont}\n');
55 fprintf(fid,'\n');
56
57 fprintf(fid,'\\begin{document} \n\n');
58
59 fprintf(fid,'\\title{\n');
60 for ii=1:length(myText); fprintf(fid,[myText{ii} '\\\\ \n']); end;
61 fprintf(fid,'}\n\n');
62 fprintf(fid,'\\date{\\today}\n\n');
63 fprintf(fid,'\\frame{\\titlepage}\n\n');
64
65 fprintf(fid,'\\frame{\n');
66 fprintf(fid,'\\frametitle{Table of contents}\n');
67 fprintf(fid,'\\begin{multicols}{2}\n');
68 fprintf(fid,'\\Fontvi\n');
69 fprintf(fid,'\\tableofcontents\n');
70 fprintf(fid,'\\end{multicols}\n');
71 fprintf(fid,'} \n\n');
72
73 if ~isempty(myRdm);
74 fprintf(fid,'\\frame{\n');
75 fprintf(fid,'\\section{README}\n');
76 fprintf(fid,'\\Fontvi\n');
77 for pp=1:length(myRdm);
78 fprintf(fid,[myRdm{pp} '\n\n']);
79 end;
80 fprintf(fid,'} \n\n');
81 end;
82
83 fclose(fid);
84 end;
85 myFigNumTex=0;
86 mySection='';
87 eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
88 end;
89
90 %open file and go to last line
91 fid=fopen(myFile,'a+');
92 eval(['load ' myFile(1:end-4) '.mat;']);
93
94 %add title or section page (see myLev)
95 if myStep==1;
96 mySection=myText;
97 if myLev==1; fprintf(fid,'\\section{\n');
98 else; fprintf(fid,'\\subsection{\n');
99 end;
100 fprintf(fid,mySection);
101 fprintf(fid,'} \n\n');
102 end;
103
104 %add a figure plus caption (see myFig)
105 if myStep==2;
106 figure(myFig);
107 drawnow;
108 myFigNumTex=myFigNumTex+1;
109 nn=strfind(myFile,filesep);
110 if ~isempty(nn);
111 dirTex=myFile(1:nn(end)); fileTex=myFile(nn(end)+1:end-4);
112 else;
113 dirTex='./'; fileTex=myFile(1:end-4)
114 end;
115 %print the very figure
116 print(myFig,'-depsc',[dirTex fileTex '.fig' num2str(myFigNumTex)]);
117 close;
118 %add figure to text file
119 fprintf(fid,'\\frame{ \n');
120 fprintf(fid,['\\frametitle{' mySection '} \n']);
121 fprintf(fid,'\\begin{figure}[tbh] \\centering \n');
122 % fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');
123 fprintf(fid,'\\includegraphics[width=0.75\\textwidth]');
124 fprintf(fid,['{' fileTex '.fig' num2str(myFigNumTex) '}\n']);
125 fprintf(fid,'\\caption{');
126 for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;
127 fprintf(fid,'} \\end{figure} \n');
128 fprintf(fid,'} \n\n');
129 end;
130
131 %add a paragraph
132 if myStep==3;
133 for ii=1:length(myText);
134 fprintf(fid,[myText{ii} '\n']);
135 end;
136 end;
137
138 %finish file
139 if myStep==4; fprintf(fid,'\n\n \\end{document} \n\n'); end;
140
141 %close file
142 fprintf(fid,'\n\n');
143 fclose(fid);
144 eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
145
146 %compile
147 if myStep==5;
148 dirOrig=pwd;
149 nn=strfind(myFile,filesep);
150 if ~isempty(nn);
151 cd(myFile(1:nn(end))); fileTex=myFile(nn(end)+1:end-4);
152 else;
153 fileTex=myFile(1:end-4);
154 end;
155 system(['latex ' fileTex]);
156 system(['latex ' fileTex]);
157 system(['dvipdf ' fileTex]);
158 cd(dirOrig);
159 end;
160
161
162 %compile
163 if myStep==6&ispc;
164 fprintf('warning : compiling tex to pdf is bypassed on PCs\n');
165 end;
166
167 if myStep==6&~ispc;
168 dirOrig=pwd;
169 nn=strfind(myFile,filesep);
170 if ~isempty(nn);
171 cd(myFile(1:nn(end))); fileTex=myFile(nn(end)+1:end-4);
172 else;
173 fileTex=myFile(1:end-4);
174 end;
175 delete([fileTex '.fig*']);
176 delete([fileTex '.aux']);
177 delete([fileTex '.log']);
178 delete([fileTex '.out']);
179 delete([fileTex '.dvi']);
180 cd(dirOrig);
181 end;

  ViewVC Help
Powered by ViewVC 1.1.22