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

Annotation 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.14 - (hide annotations) (download)
Mon Mar 14 15:56:49 2016 UTC (9 years, 4 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.13: +17 -2 lines
- diags_display.m: set addToTex=1 but fileTex='' to go through write2tex
  but simply to add figure captions (when using diags_display directly).
- write2tex.m: add call to gcmfaces_caption (also when fileTex='') and
  save figures (atfter print to eps and activation of caption).
- gcmfaces_caption.m: output captionHandle; include 'Children' in
  visibility switch; rename temporary variables as gfCapTmp and gfCapTmppp;
  revise uipanel aspect and position.

1 gforget 1.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 gforget 1.3 % 0 create file starting with title page (see myText)
6     % 1 add section or subsection (see myLev)
7 gforget 1.1 % 2 add a figure plus caption (see myFig)
8     % 3 add a paragraph
9     % 4 finish file
10 gforget 1.6 % 5 compile (latex x 2 then dvipdf)
11     % 6 remove temporary files (incl. *fig*.ps)
12 gforget 1.1 %optional myText is a cell array of text lines (for myStep=1 to 2)
13     % myLev is the title level (for myStep=1)
14 gforget 1.3 % 1=section, 2=subsection (not yet implemented)
15 gforget 1.1 % myFig is a figure handle (for myStep=2)
16    
17 gforget 1.14 if isempty(myFile)&myStep==2;
18     myText=varargin{1};
19     myText=[myText{:}];
20     gcmfaces_caption(myText);
21     return;
22     elseif isempty(myFile);
23 gforget 1.4 %if no file name, then do nothing
24     return;
25     end;
26     if iscell(myFile);
27     %extecute alternative command (myFile{1}) passing rest as arguments
28     eval([myFile{1} '(myFile{2:end});']);
29     return;
30     end;
31    
32    
33 gforget 1.8 myText=[]; myLev=[]; myFig=[]; myRdm=[];
34 gforget 1.3 if myStep<4; myText=varargin{1}; end;
35 gforget 1.8 if myStep==0; myRdm=varargin{2};
36     elseif myStep==1; myLev=varargin{2};
37 gforget 1.1 elseif myStep==2; myFig=varargin{2};
38     end;
39    
40 gforget 1.10 %format use for printing out plots :
41     frmt='eps';
42     if ispc; frmt='jpg'; end;
43    
44 gforget 1.1 %create file starting with write2tex.header
45     if myStep==0;
46     test0=dir(myFile);
47     if ~isempty(test0);
48     test0=input(['you are about to overwrite ' myFile ' !!! \n type 1 to proceed, 0 to stop \n']);
49     else;
50     test0=1;
51     end;
52     if ~test0;
53     return;
54     else;
55 gforget 1.3 fid=fopen(myFile,'w');
56    
57     fprintf(fid,'\\documentclass[12pt]{beamer}\n');
58     fprintf(fid,'%%a nice series of examples for the beamer class:\n');
59     fprintf(fid,'%%http://www.informatik.uni-freiburg.de/~frank/ENG/beamer/example/beamer-class-example-en-5.html\n');
60 gforget 1.8 fprintf(fid,'\\usepackage{multicol}\n');
61    
62     fprintf(fid,'\n');
63     fprintf(fid,'\\newcommand\\Fontvi{\\fontsize{6}{7.2}\\selectfont}\n');
64     fprintf(fid,'\n');
65    
66 gforget 1.3 fprintf(fid,'\\begin{document} \n\n');
67    
68     fprintf(fid,'\\title{\n');
69     for ii=1:length(myText); fprintf(fid,[myText{ii} '\\\\ \n']); end;
70     fprintf(fid,'}\n\n');
71     fprintf(fid,'\\date{\\today}\n\n');
72     fprintf(fid,'\\frame{\\titlepage}\n\n');
73    
74 gforget 1.8 fprintf(fid,'\\frame{\n');
75     fprintf(fid,'\\frametitle{Table of contents}\n');
76     fprintf(fid,'\\begin{multicols}{2}\n');
77     fprintf(fid,'\\Fontvi\n');
78     fprintf(fid,'\\tableofcontents\n');
79     fprintf(fid,'\\end{multicols}\n');
80 gforget 1.3 fprintf(fid,'} \n\n');
81    
82 gforget 1.8 if ~isempty(myRdm);
83     fprintf(fid,'\\frame{\n');
84     fprintf(fid,'\\section{README}\n');
85     fprintf(fid,'\\Fontvi\n');
86     for pp=1:length(myRdm);
87     fprintf(fid,[myRdm{pp} '\n\n']);
88     end;
89     fprintf(fid,'} \n\n');
90     end;
91    
92 gforget 1.3 fclose(fid);
93 gforget 1.1 end;
94 gforget 1.2 myFigNumTex=0;
95 gforget 1.3 mySection='';
96     eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
97 gforget 1.1 end;
98    
99     %open file and go to last line
100     fid=fopen(myFile,'a+');
101 gforget 1.3 eval(['load ' myFile(1:end-4) '.mat;']);
102 gforget 1.1
103     %add title or section page (see myLev)
104 gforget 1.3 if myStep==1;
105     mySection=myText;
106 gforget 1.5 if myLev==1; fprintf(fid,'\\section{\n');
107     else; fprintf(fid,'\\subsection{\n');
108     end;
109 gforget 1.3 fprintf(fid,mySection);
110     fprintf(fid,'} \n\n');
111     end;
112 gforget 1.1
113     %add a figure plus caption (see myFig)
114     if myStep==2;
115     figure(myFig);
116 gforget 1.2 drawnow;
117 gforget 1.14 %add (but hide) caption directly in figure
118     captionHandle=gcmfaces_caption([myText{:}]);
119     set(captionHandle,'Visible','off');
120     set(get(captionHandle,'Children'),'Visible','off');
121     %set file names
122 gforget 1.2 myFigNumTex=myFigNumTex+1;
123 gforget 1.12 [dirTex,fileTex,EXT] = fileparts(myFile);
124 gforget 1.14 %print figure
125 gforget 1.10 if strcmp(frmt,'eps');
126     print(myFig,'-depsc',[dirTex fileTex '_fig' num2str(myFigNumTex) '.eps']);
127     elseif strcmp(frmt,'jpg');
128     print(myFig,'-djpeg90',[dirTex fileTex '_fig' num2str(myFigNumTex) '.jpg']);
129 gforget 1.11 elseif strcmp(frmt,'png');
130 gforget 1.10 print(myFig,'-dpng',[dirTex fileTex '_fig' num2str(myFigNumTex) '.png']);
131     end
132 gforget 1.14 %save figure (with visible caption)
133     set(captionHandle,'Visible','on');
134     set(get(captionHandle,'Children'),'Visible','on');
135     saveas(myFig,[dirTex fileTex '_fig' num2str(myFigNumTex)],'fig');
136     %close figure
137 gforget 1.2 close;
138 gforget 1.1 %add figure to text file
139 gforget 1.2 fprintf(fid,'\\frame{ \n');
140 gforget 1.3 fprintf(fid,['\\frametitle{' mySection '} \n']);
141 gforget 1.1 fprintf(fid,'\\begin{figure}[tbh] \\centering \n');
142     % fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');
143 gforget 1.3 fprintf(fid,'\\includegraphics[width=0.75\\textwidth]');
144 gforget 1.11 fprintf(fid,['{' fileTex '_fig' num2str(myFigNumTex) '.' frmt '}\n']);
145 gforget 1.1 fprintf(fid,'\\caption{');
146     for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;
147     fprintf(fid,'} \\end{figure} \n');
148 gforget 1.2 fprintf(fid,'} \n\n');
149 gforget 1.1 end;
150    
151     %add a paragraph
152     if myStep==3;
153     for ii=1:length(myText);
154     fprintf(fid,[myText{ii} '\n']);
155     end;
156     end;
157    
158     %finish file
159     if myStep==4; fprintf(fid,'\n\n \\end{document} \n\n'); end;
160    
161     %close file
162     fprintf(fid,'\n\n');
163     fclose(fid);
164 gforget 1.3 eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
165 gforget 1.1
166     %compile
167 gforget 1.6 if myStep==5;
168 gforget 1.13 fprintf('\nNow we can attempt to compile the tex file from within Matlab. \n');
169     fprintf('If the latex implementation is incomplete then this may fail, and \n');
170     fprintf('user should then abort and compile the tex file from outside Matlab. \n');
171     fprintf('The beamer class is required by in particular. In Matlab, if prompted \n');
172     fprintf(' with a question mark then typing ''quit'' will abort compilation. \n');
173     test0=input('\n type 1 to proceed or 0 to skip this attempt\n');
174     if test0;
175     dirOrig=pwd;
176     [PATHSTR,fileTex,EXT] = fileparts(myFile);
177     cd(PATHSTR);
178     system(['latex ' fileTex]);
179     system(['latex ' fileTex]);
180     system(['dvipdf ' fileTex]);
181     cd(dirOrig);
182     end;
183 gforget 1.1 end;
184    
185    
186     %compile
187 gforget 1.9 if myStep==6&ispc;
188     fprintf('warning : compiling tex to pdf is bypassed on PCs\n');
189     end;
190    
191     if myStep==6&~ispc;
192 gforget 1.1 dirOrig=pwd;
193 gforget 1.9 nn=strfind(myFile,filesep);
194 gforget 1.1 if ~isempty(nn);
195 gforget 1.6 cd(myFile(1:nn(end))); fileTex=myFile(nn(end)+1:end-4);
196 gforget 1.1 else;
197     fileTex=myFile(1:end-4);
198     end;
199 gforget 1.11 delete([fileTex '_fig*']);
200 gforget 1.9 delete([fileTex '.aux']);
201     delete([fileTex '.log']);
202     delete([fileTex '.out']);
203     delete([fileTex '.dvi']);
204 gforget 1.1 cd(dirOrig);
205     end;

  ViewVC Help
Powered by ViewVC 1.1.22