-
Notifications
You must be signed in to change notification settings - Fork 0
/
sym2latex.m
executable file
·57 lines (56 loc) · 1.47 KB
/
sym2latex.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
%
% sym2latex.m
%
% Created by Léa Strobino.
% Copyright 2016 hepia. All rights reserved.
%
function s = sym2latex(s)
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)'];
if isa(s,'sym')
s = latex(s);
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('sym2latex: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