-
Notifications
You must be signed in to change notification settings - Fork 0
/
totaldiff.m
executable file
·60 lines (59 loc) · 1.68 KB
/
totaldiff.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
%
% totaldiff.m
%
% Created by Léa Strobino.
% Copyright 2016 hepia. All rights reserved.
%
function s = totaldiff(varargin)
greek = ['(alpha|beta|chi|delta|epsilon|eta|gamma|iota|kappa|lambda|'...
'mu|nu|omega|phi|psi|rho|sigma|tau|theta|upsilon|xi|zeta|'...
'Alpha|Beta|Chi|Delta|Epsilon|Eta|Gamma|Iota|Kappa|Lambda|'...
'Mu|Nu|Omega|Phi|Psi|Rho|Sigma|Tau|Theta|Upsilon|Xi|Zeta)'];
s = ''; %#ok<*AGROW>
for i = 2:nargin
c = latex(simplify(diff(varargin{1},varargin{i})));
s = [s '+\left|' c '\right|\cdot\Delta ' regexprep(inputname(i),greek,'\\$1')];
end
s = ['\Delta ' regexprep(inputname(1),greek,'\\$1') ' = ' s(2:end)];
s = strrep(s,'_{V}\mathrm{ar}','');
s = strrep(s,'\mathrm{log}','\ln');
s = regexprep(s,['\\mathrm{' greek '}'],'\\$1');
s = regexprep(s,'\\mathrm{(.*?)}','$1');
s = regexprep(s,'\\!','');
if ~nargout
if ispc
fs = 14;
else
fs = 20;
end
h = figure(...
'Color',[1 1 1],...
'DockControls','off',...
'MenuBar','none',...
'Resize','off',...
'Toolbar','none',...
'WindowStyle','normal');
a = axes(...
'Units','pixels',...
'Parent',h,...
'Position',[10 10 1 1],...
'Visible','off');
t = text(0,0,['$' s '$'],...
'Units','pixels',...
'FontSize',fs,...
'HorizontalAlignment','left',...
'Interpreter','LaTeX',...
'Parent',a,...
'VerticalAlignment','bottom');
ss = get(0,'ScreenSize');
w = warning('off','MATLAB:handle_graphics:exceptions:SceneNode');
e = get(t,'Extent');
warning(w);
if all(e == 0)
close(h);
warning('totaldiff:LatexSyntaxError','Syntax error in LaTeX string.');
else
set(h,'Position',[(ss(3:4)-e(3:4))/2-10 e(3:4)+20]);
set(a,'Position',[10 10 e(3:4)]);
end
end