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

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

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

revision 1.1 by gforget, Tue Jun 28 20:58:03 2011 UTC revision 1.5 by gforget, Wed Jan 29 02:20:16 2014 UTC
# Line 2  function []=write2tex(myFile,myStep,vara Line 2  function []=write2tex(myFile,myStep,vara
2  %object:        create/increment/complete/compile a tex file from within matlab  %object:        create/increment/complete/compile a tex file from within matlab
3  %input:         myFile is the file name  %input:         myFile is the file name
4  %               myStep is the operation to perform on the tex file  %               myStep is the operation to perform on the tex file
5  %                       0   create file starting with write2tex.header  %                       0   create file starting with title page (see myText)
6  %(not yet)              1   add title or section page (see myLev)  %                       1   add section or subsection (see myLev)
7  %                       2   add a figure plus caption (see myFig)  %                       2   add a figure plus caption (see myFig)
8  %                       3   add a paragraph  %                       3   add a paragraph
9  %                       4   finish file  %                       4   finish file
# Line 11  function []=write2tex(myFile,myStep,vara Line 11  function []=write2tex(myFile,myStep,vara
11  %                       -5  compile solely  %                       -5  compile solely
12  %optional       myText is a cell array of text lines (for myStep=1 to 2)  %optional       myText is a cell array of text lines (for myStep=1 to 2)
13  %               myLev is the title level (for myStep=1)  %               myLev is the title level (for myStep=1)
14  %                       0=manuscript title, 1=section, 2=subsection  %                       1=section, 2=subsection (not yet implemented)
15  %               myFig is a figure handle (for myStep=2)  %               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=[];  myText=[]; myLev=[]; myFig=[];
29  if myStep>0&myStep<4; myText=varargin{1}; end;  if myStep<4; myText=varargin{1}; end;
30  if myStep==1; myLev=varargin{2};  if myStep==1; myLev=varargin{2};
31  elseif myStep==2; myFig=varargin{2};  elseif myStep==2; myFig=varargin{2};
32  end;  end;
# Line 31  if myStep==0; Line 42  if myStep==0;
42      if ~test0;      if ~test0;
43          return;          return;
44      else;      else;
45          tmp1=which('write2tex');          fid=fopen(myFile,'w');
46          eval(['!\cp -f ' tmp1(1:end-2) '.header ' myFile ]);  
47            fprintf(fid,'\\documentclass[12pt]{beamer}\n');
48            fprintf(fid,'%%a nice series of examples for the beamer class:\n');
49            fprintf(fid,'%%http://www.informatik.uni-freiburg.de/~frank/ENG/beamer/example/beamer-class-example-en-5.html\n');
50            fprintf(fid,'\\begin{document} \n\n');
51    
52            fprintf(fid,'\\title{\n');
53            for ii=1:length(myText); fprintf(fid,[myText{ii} '\\\\ \n']); end;
54            fprintf(fid,'}\n\n');
55            fprintf(fid,'\\date{\\today}\n\n');
56            fprintf(fid,'\\frame{\\titlepage}\n\n');
57    
58            fprintf(fid,'\\frame{');
59            fprintf(fid,'\\frametitle{Table of contents}');
60            fprintf(fid,'\\tableofcontents');
61            fprintf(fid,'} \n\n');
62    
63            fclose(fid);
64      end;      end;
65        myFigNumTex=0;
66        mySection='';
67        eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
68  end;  end;
69    
70  %open file and go to last line  %open file and go to last line
71  fid=fopen(myFile,'a+');  fid=fopen(myFile,'a+');
72    eval(['load ' myFile(1:end-4) '.mat;']);
73    
74  %add title or section page (see myLev)  %add title or section page (see myLev)
75    if myStep==1;
76        mySection=myText;
77        if myLev==1; fprintf(fid,'\\section{\n');
78        else; fprintf(fid,'\\subsection{\n');
79        end;
80        fprintf(fid,mySection);
81        fprintf(fid,'} \n\n');
82    end;
83    
84  %add a figure plus caption (see myFig)  %add a figure plus caption (see myFig)
85  if myStep==2;  if myStep==2;
86      figure(myFig);      figure(myFig);
87        drawnow;
88        myFigNumTex=myFigNumTex+1;
89      nn=strfind(myFile,'/');      nn=strfind(myFile,'/');
90      if ~isempty(nn);      if ~isempty(nn);
91          dirTex=myFile(1:nn); fileTex=myFile(nn+1:end-4);          dirTex=myFile(1:nn(end)); fileTex=myFile(nn(end)+1:end-4);
92      else;      else;
93          dirTex='./'; fileTex=myFile(1:end-4)          dirTex='./'; fileTex=myFile(1:end-4)
94      end;      end;
95      %print the very figure      %print the very figure
96      print(myFig,'-depsc',[dirTex fileTex '.fig' num2str(myFig)]);      print(myFig,'-depsc',[dirTex fileTex '.fig' num2str(myFigNumTex)]);
97        close;
98      %add figure to text file      %add figure to text file
99      fprintf(fid,'\\clearpage \n');      fprintf(fid,'\\frame{ \n');
100        fprintf(fid,['\\frametitle{' mySection '} \n']);
101      fprintf(fid,'\\begin{figure}[tbh] \\centering \n');      fprintf(fid,'\\begin{figure}[tbh] \\centering \n');
102  %     fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');  %     fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');
103      fprintf(fid,'\\includegraphics[width=\\textwidth]');      fprintf(fid,'\\includegraphics[width=0.75\\textwidth]');
104      fprintf(fid,['{' fileTex '.fig' num2str(myFig) '}\n']);      fprintf(fid,['{' fileTex '.fig' num2str(myFigNumTex) '}\n']);
105      fprintf(fid,'\\caption{');      fprintf(fid,'\\caption{');
106      for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;      for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;
107      fprintf(fid,'} \\end{figure} \n');      fprintf(fid,'} \\end{figure} \n');
108      fprintf(fid,'\\clearpage \n\n');      fprintf(fid,'} \n\n');
109  end;  end;
110    
111  %add a paragraph  %add a paragraph
# Line 77  if myStep==4; fprintf(fid,'\n\n \\end{do Line 121  if myStep==4; fprintf(fid,'\n\n \\end{do
121  %close file  %close file
122  fprintf(fid,'\n\n');  fprintf(fid,'\n\n');
123  fclose(fid);  fclose(fid);
124    eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
125    
126  %compile  %compile
127  if myStep==5|myStep==-5;  if myStep==5|myStep==-5;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.22