/[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.2 by gforget, Tue Jul 5 18:52:18 2011 UTC revision 1.8 by gforget, Sat Feb 1 18:15:49 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
10  %                       5   compile and remove temporary files (incl. *fig*.ps)  %                       5   compile (latex x 2 then dvipdf)
11  %                       -5  compile solely  %                       6   remove temporary files (incl. *fig*.ps)
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  myText=[]; myLev=[]; myFig=[];  if isempty(myFile);
18  if myStep>0&myStep<4; myText=varargin{1}; end;      %if no file name, then do nothing
19  if myStep==1; myLev=varargin{2};      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};  elseif myStep==2; myFig=varargin{2};
33  end;  end;
34    
# Line 31  if myStep==0; Line 43  if myStep==0;
43      if ~test0;      if ~test0;
44          return;          return;
45      else;      else;
46          tmp1=which('write2tex');          fid=fopen(myFile,'w');
47          eval(['!\cp -f ' tmp1(1:end-2) '.header ' myFile ]);  
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;      end;
85      myFigNumTex=0;      myFigNumTex=0;
86      eval(['save ' myFile(1:end-4) '.mat myFigNumTex;']);      mySection='';
87        eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
88  end;  end;
89    
90  %open file and go to last line  %open file and go to last line
91  fid=fopen(myFile,'a+');  fid=fopen(myFile,'a+');
92  eval(['load ' myFile(1:end-4) '.mat myFigNumTex;']);  eval(['load ' myFile(1:end-4) '.mat;']);
93    
94  %add title or section page (see myLev)  %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)  %add a figure plus caption (see myFig)
105  if myStep==2;  if myStep==2;
# Line 60  if myStep==2; Line 117  if myStep==2;
117      close;      close;
118      %add figure to text file      %add figure to text file
119      fprintf(fid,'\\frame{ \n');      fprintf(fid,'\\frame{ \n');
120        fprintf(fid,['\\frametitle{' mySection '} \n']);
121      fprintf(fid,'\\begin{figure}[tbh] \\centering \n');      fprintf(fid,'\\begin{figure}[tbh] \\centering \n');
122  %     fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');  %     fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');
123      fprintf(fid,'\\includegraphics[width=0.85\\textwidth]');      fprintf(fid,'\\includegraphics[width=0.75\\textwidth]');
124      fprintf(fid,['{' fileTex '.fig' num2str(myFigNumTex) '}\n']);      fprintf(fid,['{' fileTex '.fig' num2str(myFigNumTex) '}\n']);
125      fprintf(fid,'\\caption{');      fprintf(fid,'\\caption{');
126      for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;      for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;
# Line 83  if myStep==4; fprintf(fid,'\n\n \\end{do Line 141  if myStep==4; fprintf(fid,'\n\n \\end{do
141  %close file  %close file
142  fprintf(fid,'\n\n');  fprintf(fid,'\n\n');
143  fclose(fid);  fclose(fid);
144  eval(['save ' myFile(1:end-4) '.mat myFigNumTex;']);  eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
145    
146  %compile  %compile
147  if myStep==5|myStep==-5;  if myStep==5;
148      dirOrig=pwd;      dirOrig=pwd;
149      nn=strfind(myFile,'/');      nn=strfind(myFile,'/');
150      if ~isempty(nn);      if ~isempty(nn);
151          cd(myFile(1:nn)); fileTex=myFile(nn+1:end-4);          cd(myFile(1:nn(end))); fileTex=myFile(nn(end)+1:end-4);
152      else;      else;
153          fileTex=myFile(1:end-4);          fileTex=myFile(1:end-4);
154      end;      end;
# Line 102  end; Line 160  end;
160    
161    
162  %compile  %compile
163  if myStep==5;  if myStep==6;
164      dirOrig=pwd;      dirOrig=pwd;
165      nn=strfind(myFile,'/');      nn=strfind(myFile,'/');
166      if ~isempty(nn);      if ~isempty(nn);
167          cd(myFile(1:nn)); fileTex=myFile(nn+1:end-4);          cd(myFile(1:nn(end))); fileTex=myFile(nn(end)+1:end-4);
168      else;      else;
169          fileTex=myFile(1:end-4);          fileTex=myFile(1:end-4);
170      end;      end;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.22