function varargout = publish_plus( fname, format, varargin )
% Do PUBLISH and compile LaTeX output to dvi, ps or pdf
%
% fname : m-file name
% format : either any of those supported by publish or one of
% {dvi, ps, pdf}
% varargin : any argument you might want to pass to <a href="matlab:help publish">publish</a> apart from file
% name and format.
%
% Requirements
% In order to being able to publish from LaTeX you will need
% LaTeX compiler. The output will be of format *.dvi. For
% other formats like *.pdf or *.ps you will need additional
% processors (e.g. dvips or pdflatex). All of this
% additional software is freely availible in
% MiKTeX (<a href="matlab: web('www.miktex.org')">www.miktex.org</a>)
%
% Example
% publish_plus( 'delsqdemo', 'pdf', '.\html' );
% This will generate a published m-file in the PDF format in the
% default html subfolder of the script location (with some
% additional clutter from LaTeX...)
%
% Notes
% The XSLT processor used to convert the output to LaTeX seems to
% dislike relative paths. So you should use PWD in combination
% with FULLFILE. In this path however you can use "..".
%
% TODO's When outputting the graphics, get ML to use the smallest
% possible paper size or else insert the appropriate clipping
% commands in the LaTeX output.
%
% Allow for functions to be published (e.g. via an additional
% cell-array argument containing the arguments to the function.)
%
% Implement "pre-processor" instructions to include other
% functions into the published file in order to create more
% complete reports. Not being able to do so is particularly
% annoying when publishing a driver script which only calls the
% actual programs which contain the real information.
%
% See also: PUBLISH
%--------------------------------------------------------------------------
% Author : Michael Wild
% Email : themiwi@student.ethz.ch
% Copyright 2005-2005
%
% Created : 2005.04.22, 01:07
% Version : 0.1 (just hacked it together :-)
%
% DISCLAIMER
% ==========
%
% The software provided by me with this Matlab function and the altered
% version of the original PUBLISH function by The Mathworks are purely
% experimental. You use it at your own risk. I am not responible for any
% harm or damage caused by it.
%LATEXPATH%
%PDFLATEXPATH%
%DVIPSPATH%
switch format
case {'dvi','ps'}
pubformat = 'latex';
proclatex = true;
case 'pdf'
pubformat = 'pdflatex';
proclatex = true;
otherwise
pubformat = format;
proclatex = false;
end
if nargin > 2
opts = varargin{1};
else
opts = struct();
end
opts.format = pubformat;
file = publish( fname, opts );
if proclatex
command{1} = [latexpath,'"',file,'"'];
[p,f,e] = fileparts(file);
currdir = pwd;
cd(p);
switch format
case 'dvi'
% For future changes...
case 'ps'
command{end+1} = [dvipath,'"',fullfile(p,[f,'.dvi']),'"'];
case 'pdf'
command = [];
command{1} = [pdfpath,'"',fullfile(p,[f,'.tex']),'"'];
end
for j=1:2 % most latex stuff needs to be run twice
for i=1:length(command)
system(command{i});
end
end
cd(currdir);
file = fullfile(p,[f,'.',format]);
end
if nargout > 0
varargout{1} = file;
end