-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
185 lines (167 loc) · 4.05 KB
/
index.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ASCIIMath 在线编辑器</title>
<style type="text/css" media="screen">
.cls{
clear:both;
}
#tools li{
font-size:2em;
list-style-type:none;
float:left;
margin-right:20px;
}
#tools .short{
font-size:0.6em;
}
#container{
position: relative;
width:100%;
clear:both;
height:500px;
margin:30px 0 0 0;
}
#editor {
float:left;
width:50%;
height:100%;
}
#display {
float:left;
width:50%;
height:100%;
font-size:1.5em;
}
</style>
</head>
<body>
<div id='tools'>
<h2>括号内字符为快捷键,比如Shift+A表示Ctrl+Shift+A即可快速输入 α,D表示用Ctrl+D快速输入δ。也可点击字符插入。</h2>
<div>
<h3>常用字符: </h3>
<ul id='letters'>
<!-- <li>`alpha`<span class='short'>(A)</span></li> <li>`beta`<span class='short'>(B)</span></li> <li>`chi`<span class='short'>(C)</span></li> <li>`delta`<span class='short'>(D)</span></li>
-->
</ul><div class='cls' /> </div>
<div>
<h3>常用操作符号 </h3>
<ul id='symbols'>
<!-- <li>`sqrtx`<span class='short'>(S)</span></li> <li>`root3x`<span class='short'>(R)</span></li> -->
</ul><div class='cls' /></div>
</div>
<div id='container'>
<h2>在下面编辑,右边可实时显示公式</h2>
<div id="editor">
x = (-b +- sqrt(b^2-4ac))/(2a) .
</div>
<div id='display'>
`x = (-b +- sqrt(b^2-4ac))/(2a) .`
</div>
</div>
<script src="http://cdn.staticfile.org/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/ace/1.1.3/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="http://cdn.staticfile.org/mathjax/2.4.0/MathJax.js?config=AM_HTMLorMML-full"></script>
<script>
$('#editor').css({'font-size':'16px'} );
var editor = ace.edit("editor");
// editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/latex");
editor.getSession().on('change', function(e) {
//$('#display').html(editor.getValue() );
var math = MathJax.Hub.getAllJax("display")[0];
MathJax.Hub.Queue(["Text",math, editor.getValue()]);
});
var lettersConfig=[['Shift+A', 'alpha'],
['B', 'beta'],
['Shift+C', 'chi'],
['D', 'delta'],
['Shift+D', 'Delta'],
['E', 'epsilon'],
['', 'varepsilon'],
['Shift+E', 'eta'],
['G', 'gamma'],
['Shift+G', 'Gamma'],
['I', 'iota'],
['K', 'kappa'],
['L', 'lambda'],
['Shift+L', 'Lambda'],
['M', 'mu'],
['N', 'nu'],
['O', 'omega'],
['Shift+O', 'Omega'],
['','phi'],
['Shift+V', 'varphi'],
['','Phi'],
['P', 'pi'],
['Shift+P', 'Pi'],
['','psi'],
['','Psi'],
['', 'rho'],
['', 'sigma'],
['Shift+S', 'Sigma'],
['T', 'tau'],
['Shift+T', 'theta'],
['', 'vartheta'],
['','Theta'],
['U', 'upsilon'],
['', 'xi'],
['Shift+X', 'Xi'],
['Z', 'zeta'] ];
var symbolsConfig = [
['S','sqrtx'],
['R','root3x'],
['','int'],
['','oint'],
['','del'],
['','grad'],
['','oo'],
['','aleph'],
['','sum'],
['','prod'],
['','xx'],
['','in'],
['','!in'],
['','sub'],
['','sup'],
['','sube'],
['','supe'],
['','-='],
['','~='],
['','~~'],
['','prop'],
['','hat x'],
['','bar x'],
['','ul x'],['','vec x'],['','dot x'],['','ddot x'],['','AA'],['','EE'],
];
var applyConfig = function(id, config){
$.each(config, function(index,value){
var key = value[0], val = value[1];
var letter = "<li title='"+val+"'>`"+val+"`";
if( key ){
letter += "<span class='short'>("+key+")</span>";
editor.commands.addCommand({
name: 'myCommand'+ key,
bindKey: {win: 'Ctrl+'+key, mac: 'Command+'+key},
exec: function(editor) {
//...
editor.insert(val);
},
readOnly: true // false if this command should not apply in readOnly mode
});
}
letter += "</li>";
$(id).append(letter);
});
}
applyConfig('#letters',lettersConfig);
applyConfig('#symbols',symbolsConfig);
setTimeout(function(){editor.focus();editor.gotoLine(2,33);}, 1000);
$('#tools ul').on('click','li',function (e) {
editor.insert( $(this).attr('title') );
editor.focus();
})
</script>
</body>
</html>