| AniLaTeX=animateinlineLaTeX(var1,var2,var3,var4,var5,var6)
|
function AniLaTeX=animateinlineLaTeX(var1,var2,var3,var4,var5,var6)
% animateinlineLaTeX generates LaTeX code for animations
% using animateinline in the LaTeX animate package.
%
% The animation code is done in two steps.
% i, A data structure is created.
% ii, The code is written.
%
% i, The data structure AniLaTeX is initiated by an
% empty matrix [] (AniLaTeX=[];)
%
% Frames are inserted using the command:
%
% AniLaTeX=animateinlineLaTeX(AniLaTeX,fileName,figureDirectory, ...
% includegraphicsOptions,frameRate,star);
%
% (4 or more in arguments)
%
% AniLaTeX - data structure
% fileName - name of graphics file (string) (for example "fig.eps")
% figureDirectory - directory where the graphics file is. (string)
% Information to LaTeX. (same directory, empty string '')
% includegraphicsOptions - Information to \includegraphics. (string)
% (information inside [] like trimming, rotation etc.)
% (no infromation, emty string '')
% (see documentation for \includegraphics)
% frameRate - (optional) framerate (default 1)
% (see documentation for animateinline)
% star - (optional) '*' or '' (default). If the frame should be marked with a star.
% That means a pause is inserted into the animation.
% (see documentation for animateinline)
%
%
% ii, The LaTeX code is generated using the command:
%
% animateinlineLaTeX(AniLaTeX,fileName,animateinlineOptions);
%
% (3 in arguments)
%
% AniLaTeX - data structure
% fileName - name of TEX-file (no extension like .tex) (string)
% animateinlineOptions - Information to animateinline. (string)
% (information inside [] like autoplay, loop etc.)
% (see documentation for animateinline)
%
% The LaTeX code with name fileName.tex for the animation will be created.
% A batch file with name fileName.bat will be created for converting
% eps figures to pdf using epstopdf.
%
% See animateEx (examples) for more information about the usage.
%
% written by Per Bergstrm 2007-12-12
%
% Free for download at
%
% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=17813&objectType=file
%
% e-mail: per.bergstrom 'at' ltu.se
if nargin>3
fileName=var2;
figureDirectory=var3;
if nargin<6
var6='';
if nargin<5
var5=1;
end
end
includegraphicsOptions=var4;
frameRate=var5;
star=var6;
if isempty(var1)
AniLaTeX=cell(1,5);
else
AniLaTeX=var1;
AniLaTeX=[AniLaTeX;cell(1,5)];
end
AniLaTeX{end,1}=includegraphicsOptions;
AniLaTeX{end,2}=figureDirectory;
AniLaTeX{end,3}=fileName;
if ischar(frameRate)
AniLaTeX{end,4}=str2num(frameRate);
else
AniLaTeX{end,4}=frameRate;
end
if length(star)==1
if or(or(star=='*',star=='p'),star=='P')
AniLaTeX{end,5}='*';
end
elseif length(star)==5
if or(or(star=='pause',star=='PAUSE'),star=='Pause')
AniLaTeX{end,5}='*';
end
end
elseif nargin==3
AniLaTeX=var1;
fileName=var2;
animateinlineOptions=var3;
if length(fileName)>4
if or(or(fileName(end-3:end)=='.tex',fileName(end-3:end)=='.eps'),fileName(end-3:end)=='.pdf')
fileName=fileName(1:end-4);
end
end
fileName(find(fileName==' '))='';
fileName(find(fileName=='.'))='';
% .tex fil
fid = fopen([fileName,'.tex'],'w');
fprintf(fid,['%% Insert\n']);
fprintf(fid,['%% \\input{',fileName,'}\n']);
fprintf(fid,['%% in your original TEX file.\n']);
fprintf(fid,'%% Requires the animate package!\n');
fprintf(fid,'%% http://www.ctan.org/tex-archive/macros/latex/contrib/animate/\n');
fprintf(fid,'%% Include the packages \n');
fprintf(fid,'%% \\usepackage{animate} \n');
fprintf(fid,'%% \\usepackage{graphicx} \n');
fprintf(fid,'%% in the preamble of the original LaTeX document.\n');
fprintf(fid,'%% \n');
fprintf(fid,'%% TEX file generated by animateinlineLaTeX.\n');
fprintf(fid,'%% animateinlineLaTeX is written by Per Bergstrom \n');
fprintf(fid,'%% and is free for download at \n');
fprintf(fid,'%% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=17813&objectType=file\n\n\n');
disp(' ');
disp('Creates a TEX file containing the animation to be inserted into the original TEX file.');
disp([fileName,'.tex']);
disp(' ');
if isempty(AniLaTeX{end,4})
frrt=1;
else
frrt=AniLaTeX{end,4};
end
fprintf(fid,['\\begin{animateinline}[',animateinlineOptions,']{',num2str(frrt),'}\n\n']);
for i=1:size(AniLaTeX,1)
figureDirectory=AniLaTeX{i,2};
if length(figureDirectory)>1
if figureDirectory(1)=='\'
if figureDirectory(2)~='\'
figureDirectory=['\',figureDirectory,' '];
else
figureDirectory=[figureDirectory,' '];
end
else
figureDirectory(find(figureDirectory=='\'))='/';
if figureDirectory(end)~='/'
figureDirectory=[figureDirectory,'/'];
end
end
elseif length(figureDirectory)>0
figureDirectory(find(figureDirectory=='\'))='/';
if figureDirectory(end)~='/'
figureDirectory=[figureDirectory,'/'];
end
end
graphicsfile=AniLaTeX{i,3};
if length(graphicsfile)>4
if or(or(graphicsfile((end-3):end)=='.eps',graphicsfile((end-3):end)=='.jpg'),graphicsfile((end-3):end)=='.pdf')
graphicsfile=graphicsfile(1:(end-4));
end
end
fprintf(fid,['\\includegraphics[',AniLaTeX{i,1},']{',figureDirectory,graphicsfile,'} \n']);
if i<size(AniLaTeX,1)
if isempty(AniLaTeX{i,4})
frrt=1;
else
frrt=AniLaTeX{i,4};
end
fprintf(fid,['\\newframe',AniLaTeX{i,5},'[',num2str(frrt),'] \n']);
end
end
fprintf(fid,'\n\\end{animateinline} \n');
fclose(fid);
% .bat fil
fid = fopen([fileName,'.bat'],'w');
fprintf(fid,'@ECHO OFF\n');
fprintf(fid,['ECHO ',fileName,'\n']);
disp('Creates a batch file for converting EPS files to PDF files.');
disp([fileName,'.bat']);
disp('Requires epstopdf!');
disp(' ');
for i=1:size(AniLaTeX,1)
graphicsfile=AniLaTeX{i,3};
if length(graphicsfile)>4
if graphicsfile((end-3):end)=='.pdf'
graphicsfile=[graphicsfile(1:(end-3)),'eps'];
end
end
fprintf(fid,['epstopdf ',graphicsfile,' \n']);
end
fclose(fid);
elseif nargin==1
AniLaTeX=var1;
for i=1:size(AniLaTeX,1)
graphicsfile=AniLaTeX{i,3};
if length(graphicsfile)>4
if graphicsfile((end-3):end)=='.eps'
graphicsfile=[graphicsfile(1:(end-3)),'pdf'];
else
graphicsfile=[graphicsfile,'.pdf'];
end
else
graphicsfile=[graphicsfile,'.pdf'];
end
AniLaTeX{i,3}=graphicsfile;
end
else
error('Wrong numbers of input variables.');
end
try
if nargout==0
clear AniLaTeX;
end
end
|
|