-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg2tpx.m
executable file
·40 lines (39 loc) · 1.06 KB
/
svg2tpx.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
%
% svg2tpx.m
%
% Created by Léa Strobino.
% Copyright 2017 hepia. All rights reserved.
%
function svg2tpx(infile,outfile)
persistent TpX
if isempty(TpX)
s = 0;
if ismac
wine = '/Applications/Wine Stable.app/Contents/Resources/wine/bin/wine';
TpX = '/Applications/TpX.app/Contents/Resources/TpX.exe';
if exist(wine,'file') && exist(TpX,'file')
TpX = [wine '" "' TpX];
s = 1;
end
else
TpX = 'C:\Program Files\TpX\TpX.exe';
s = exist(TpX,'file');
if ~s
TpX = 'C:\Program Files (x86)\TpX\TpX.exe';
s = exist(TpX,'file');
end
end
if ~s
url = 'http://tpx.sourceforge.net';
error('svg2tpx:TpXNotFound',...
'TpX not found. Have you installed it? See <a href="%s">%s</a>.',url,url);
end
end
[~,~] = system(['"' TpX '" "' infile '" -o "' outfile '" -m tikz']);
h = fopen(outfile,'r');
d = fread(h,'*char')';
fclose(h);
d = regexprep(d,'<comment>.*</comment>',['<comment>Created by MATLAB ' version() '</comment>'],'once');
h = fopen(outfile,'w');
fwrite(h,d);
fclose(h);