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 |
% 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; |
30 |
end; |
end; |
31 |
|
|
32 |
|
|
33 |
myText=[]; myLev=[]; myFig=[]; |
myText=[]; myLev=[]; myFig=[]; myRdm=[]; |
34 |
if myStep<4; myText=varargin{1}; end; |
if myStep<4; myText=varargin{1}; end; |
35 |
if myStep==1; myLev=varargin{2}; |
if myStep==0; myRdm=varargin{2}; |
36 |
|
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); |
57 |
fprintf(fid,'\\documentclass[12pt]{beamer}\n'); |
fprintf(fid,'\\documentclass[12pt]{beamer}\n'); |
58 |
fprintf(fid,'%%a nice series of examples for the beamer class:\n'); |
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'); |
fprintf(fid,'%%http://www.informatik.uni-freiburg.de/~frank/ENG/beamer/example/beamer-class-example-en-5.html\n'); |
60 |
|
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 |
fprintf(fid,'\\begin{document} \n\n'); |
fprintf(fid,'\\begin{document} \n\n'); |
67 |
|
|
68 |
fprintf(fid,'\\title{\n'); |
fprintf(fid,'\\title{\n'); |
71 |
fprintf(fid,'\\date{\\today}\n\n'); |
fprintf(fid,'\\date{\\today}\n\n'); |
72 |
fprintf(fid,'\\frame{\\titlepage}\n\n'); |
fprintf(fid,'\\frame{\\titlepage}\n\n'); |
73 |
|
|
74 |
fprintf(fid,'\\frame{'); |
fprintf(fid,'\\frame{\n'); |
75 |
fprintf(fid,'\\frametitle{Table of contents}'); |
fprintf(fid,'\\frametitle{Table of contents}\n'); |
76 |
fprintf(fid,'\\tableofcontents'); |
fprintf(fid,'\\begin{multicols}{2}\n'); |
77 |
|
fprintf(fid,'\\Fontvi\n'); |
78 |
|
fprintf(fid,'\\tableofcontents\n'); |
79 |
|
fprintf(fid,'\\end{multicols}\n'); |
80 |
fprintf(fid,'} \n\n'); |
fprintf(fid,'} \n\n'); |
81 |
|
|
82 |
|
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 |
fclose(fid); |
fclose(fid); |
93 |
end; |
end; |
94 |
myFigNumTex=0; |
myFigNumTex=0; |
103 |
%add title or section page (see myLev) |
%add title or section page (see myLev) |
104 |
if myStep==1; |
if myStep==1; |
105 |
mySection=myText; |
mySection=myText; |
106 |
fprintf(fid,'\\section{\n'); |
if myLev==1; fprintf(fid,'\\section{\n'); |
107 |
|
else; fprintf(fid,'\\subsection{\n'); |
108 |
|
end; |
109 |
fprintf(fid,mySection); |
fprintf(fid,mySection); |
110 |
fprintf(fid,'} \n\n'); |
fprintf(fid,'} \n\n'); |
111 |
end; |
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,'/'); |
[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'); |
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'); |
164 |
eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']); |
eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']); |
165 |
|
|
166 |
%compile |
%compile |
167 |
if myStep==5|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,'/'); |
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)); fileTex=myFile(nn+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; |
|
eval(['!latex ' fileTex]); |
|
|
eval(['!latex ' fileTex]); |
|
|
eval(['!dvipdf ' fileTex]); |
|
|
cd(dirOrig); |
|
183 |
end; |
end; |
184 |
|
|
185 |
|
|
186 |
%compile |
%compile |
187 |
if myStep==5; |
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 |
dirOrig=pwd; |
dirOrig=pwd; |
193 |
nn=strfind(myFile,'/'); |
nn=strfind(myFile,filesep); |
194 |
if ~isempty(nn); |
if ~isempty(nn); |
195 |
cd(myFile(1:nn)); fileTex=myFile(nn+1:end-4); |
cd(myFile(1:nn(end))); fileTex=myFile(nn(end)+1:end-4); |
196 |
else; |
else; |
197 |
fileTex=myFile(1:end-4); |
fileTex=myFile(1:end-4); |
198 |
end; |
end; |
199 |
eval(['!\rm -f ' fileTex '.fig*']); |
delete([fileTex '_fig*']); |
200 |
eval(['!\rm -f ' fileTex '.aux']); |
delete([fileTex '.aux']); |
201 |
eval(['!\rm -f ' fileTex '.log']); |
delete([fileTex '.log']); |
202 |
eval(['!\rm -f ' fileTex '.out']); |
delete([fileTex '.out']); |
203 |
eval(['!\rm -f ' fileTex '.dvi']); |
delete([fileTex '.dvi']); |
204 |
cd(dirOrig); |
cd(dirOrig); |
205 |
end; |
end; |