/[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.9 by gforget, Mon Jul 28 20:54:14 2014 UTC revision 1.14 by gforget, Mon Mar 14 15:56:49 2016 UTC
# Line 14  function []=write2tex(myFile,myStep,vara Line 14  function []=write2tex(myFile,myStep,vara
14  %                       1=section, 2=subsection (not yet implemented)  %                       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);  if isempty(myFile)&myStep==2;
18        myText=varargin{1};
19        myText=[myText{:}];
20        gcmfaces_caption(myText);
21        return;
22    elseif isempty(myFile);
23      %if no file name, then do nothing      %if no file name, then do nothing
24      return;      return;
25  end;  end;
# Line 32  elseif myStep==1; myLev=varargin{2}; Line 37  elseif myStep==1; myLev=varargin{2};
37  elseif myStep==2; myFig=varargin{2};  elseif myStep==2; myFig=varargin{2};
38  end;  end;
39    
40    %format use for printing out plots :
41    frmt='eps';
42    if ispc; frmt='jpg'; end;
43    
44  %create file starting with write2tex.header  %create file starting with write2tex.header
45  if myStep==0;  if myStep==0;
46      test0=dir(myFile);      test0=dir(myFile);
# Line 105  end; Line 114  end;
114  if myStep==2;  if myStep==2;
115      figure(myFig);      figure(myFig);
116      drawnow;      drawnow;
117        %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      myFigNumTex=myFigNumTex+1;      myFigNumTex=myFigNumTex+1;
123      nn=strfind(myFile,filesep);      [dirTex,fileTex,EXT] = fileparts(myFile);
124      if ~isempty(nn);      %print figure
125          dirTex=myFile(1:nn(end)); fileTex=myFile(nn(end)+1:end-4);      if strcmp(frmt,'eps');
126      else;        print(myFig,'-depsc',[dirTex fileTex '_fig' num2str(myFigNumTex) '.eps']);
127          dirTex='./'; fileTex=myFile(1:end-4)      elseif strcmp(frmt,'jpg');
128      end;        print(myFig,'-djpeg90',[dirTex fileTex '_fig' num2str(myFigNumTex) '.jpg']);
129      %print the very figure      elseif strcmp(frmt,'png');
130      print(myFig,'-depsc',[dirTex fileTex '.fig' num2str(myFigNumTex)]);        print(myFig,'-dpng',[dirTex fileTex '_fig' num2str(myFigNumTex) '.png']);
131        end
132        %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      close;      close;
138      %add figure to text file      %add figure to text file
139      fprintf(fid,'\\frame{ \n');      fprintf(fid,'\\frame{ \n');
# Line 121  if myStep==2; Line 141  if myStep==2;
141      fprintf(fid,'\\begin{figure}[tbh] \\centering \n');      fprintf(fid,'\\begin{figure}[tbh] \\centering \n');
142  %     fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');  %     fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');
143      fprintf(fid,'\\includegraphics[width=0.75\\textwidth]');      fprintf(fid,'\\includegraphics[width=0.75\\textwidth]');
144      fprintf(fid,['{' fileTex '.fig' num2str(myFigNumTex) '}\n']);      fprintf(fid,['{' fileTex '_fig' num2str(myFigNumTex) '.' frmt '}\n']);
145      fprintf(fid,'\\caption{');      fprintf(fid,'\\caption{');
146      for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;      for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;
147      fprintf(fid,'} \\end{figure} \n');      fprintf(fid,'} \\end{figure} \n');
# Line 145  eval(['save ' myFile(1:end-4) '.mat myFi Line 165  eval(['save ' myFile(1:end-4) '.mat myFi
165    
166  %compile  %compile
167  if myStep==5;  if myStep==5;
168      dirOrig=pwd;      fprintf('\nNow we can attempt to compile the tex file from within Matlab. \n');
169      nn=strfind(myFile,filesep);      fprintf('If the latex implementation is incomplete then this may fail, and \n');
170      if ~isempty(nn);      fprintf('user should then abort and compile the tex file from outside Matlab. \n');
171          cd(myFile(1:nn(end))); fileTex=myFile(nn(end)+1:end-4);      fprintf('The beamer class is required by in particular. In Matlab, if prompted \n');
172      else;      fprintf(' with a question mark then typing ''quit'' will abort compilation. \n');
173          fileTex=myFile(1:end-4);      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;      end;
     system(['latex ' fileTex]);  
     system(['latex ' fileTex]);  
     system(['dvipdf ' fileTex]);  
     cd(dirOrig);  
183  end;  end;
184    
185    
# Line 172  if myStep==6&~ispc; Line 196  if myStep==6&~ispc;
196      else;      else;
197          fileTex=myFile(1:end-4);          fileTex=myFile(1:end-4);
198      end;      end;
199      delete([fileTex '.fig*']);      delete([fileTex '_fig*']);
200      delete([fileTex '.aux']);      delete([fileTex '.aux']);
201      delete([fileTex '.log']);      delete([fileTex '.log']);
202      delete([fileTex '.out']);      delete([fileTex '.out']);

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.22