-
Notifications
You must be signed in to change notification settings - Fork 0
/
latex2mathml.m
executable file
·37 lines (35 loc) · 1.04 KB
/
latex2mathml.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
%
% latex2mathml.m
%
% Created by Léa Strobino.
% Copyright 2016 hepia. All rights reserved.
%
function mml = latex2mathml(s)
persistent MathToWeb
if isempty(MathToWeb)
mlock();
addToClassPath([fileparts(mfilename('fullpath')) filesep 'mathtoweb.jar']);
MathToWeb = mathtoweb.engine.MathToWeb('conversion_utility');
end
o = MathToWeb.convertLatexToMathMLUtility(['$ ' s ' $'],'-line -rep -unicode');
if strcmp(o(1),'Success')
if nargout
mml = char(o(3));
else
o = java.awt.datatransfer.StringSelection(o(3));
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(o,[]);
end
else
error('latex2mathml:mathtoweb','%s',deblank(strrep(char(o(2)),char([10 10]),char(10))));
end
end
function addToClassPath(jar)
clm = com.mathworks.jmi.ClassLoaderManager.getClassLoaderManager();
classPath = clm.getClassPath();
if ~isempty(classPath)
classPath = cell(classPath)';
end
clm.setClassPath([classPath,jar]);
com.mathworks.jmi.OpaqueJavaInterface.enableClassReloading(1);
clear('java');
end