function [] = latex_labels(varargin) %function [] = latex_labels(fig_no, fig_width, file_name, % font_size, val1, str1, val2, str2, ... ) % % This function uses a slightly edited version of fragmaster.pl % (www.tat.physik.uni-tuebingen.de/~vogel/fragmaster/main.html) % to give latex labels to matlab text. % % VARIABLES % fig_no: Figure Handle (e.g. figure(1)), default is active figure. % fig_width: Width of figure in inches % file_name: name of desired file without extension % font_size: font size (in points) for labels % val/str pairs (described below): text in matlab and latex % replacement % % VAL/STR pairs % these are the pairs that are changed by the script % for example, the pair 'x', '$x$' will replace the matlab "x" % with the latex $x$. (NOTE: The matlab value cannot contain any % spaces and must be the complete string, i.e. the method will not % replace subsets of a string.) % % The function runs, Perl, LaTeX and dvips. % It requires its sister file, latex_labels.perl, and the % LaTeX style file, psfrag.sty. It is set up by default to also % include amsmath.sty. Packages can be added or removed % near the end of the file. (If you don't have psfrag.sty or % amsmath.sty, you will need to acquire them.) % % NOTES % - Some fields need editing (see top of matlab file) % - Written for implimentation on a UNIX/Linux system, % and will likely need tweaking for Windows % % EXAMPLE: % % x = [-5:5]; % y = x.^2; % plot(x,y); % xlabel('x'); % ylabel('y'); % set(gca,'fontname','times'); % latex_labels([], 6, 'yequalxsqrd', 12, 'x', '$x$', ... % 'y', '$y=x^2$'); % % RSM||13Mar07 % ramzi@dal.ca % FIELDS THAT MAY NEED EDITING perl_path = ['~/matlab/']; % path to latex_labels.perl if(length(varargin) < 6 | ... length(varargin)/2 ~= round(length(varargin)/2)) error(['Incorrect number of inputs for latex_labels.m']); end if(~isempty(varargin{1})) figure(fig_no); end if(~isnumeric(varargin{2})) error(['figure width must be a number in latex_labels.m']); else fig_width = varargin{2}; end if(~isstr(varargin{3})) error(['file name must be a string in latex_labels.m']); else file_name = varargin{3}; end if(~isnumeric(varargin{4})) error(['font size must be a number in latex_labels.m']); else font_size = varargin{4}; end % make "control file" fid = fopen([file_name,'_fm'],'w'); str = ['% Just an ordinary comment\n', ... '%\n', ... '% A special comment:\n', ... '% fmopt:width=', num2str(fig_width), 'in\n', ... '% \n', ... '% Another special comment:\n', ... '% head:\n', ... '% \usepackage{amsmath}\n', ... '% end head\n', ... '\n', ... '% psfrag commands:\n']; frags = []; m = 4; while(m < length(varargin)) frags = [frags, ... '\psfrag{', varargin{m+1}, '}{', varargin{m+2} ,'}\n']; m = m + 2; end fprintf(fid, '%s', str); fprintf(fid, '%s', frags); fclose(fid); eval(['print -depsc2 ', file_name ,'_fm.eps']); eval(['!perl -pi -e ''s/\\n/\n/g'' ', file_name ,'_fm']); eval(['!perl ', perl_path, 'latex_labels.perl ', ... file_name, '_fm ', num2str(font_size)]); eval(['!rm ', file_name, '_fm ', file_name ,'_fm.eps']);