-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
291 lines (286 loc) · 15 KB
/
index.html
File metadata and controls
291 lines (286 loc) · 15 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="Petri Salmela">
<meta name="description" content="User interface for writing mathematical equation arrays. Uses MathQuill and jQuery.">
<title>Matharray</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" type="text/css" href="mathquill/mathquill.css">
<script type="text/javascript" src="jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="mathquill/mathquill.js"></script>
<script type="text/javascript" src="jquery.matharray.js"></script>
<script type="text/javascript" src="jquery.mathpanel.js"></script>
<script type="text/javascript">
jQuery(function(){
jQuery('body').on('element_changed', function(event, data) {
event.stopPropagation();
jQuery('#matharray-data').val(JSON.stringify(data, null, 4));
localStorage.setItem('matharraydata', JSON.stringify(data));
});
jQuery('#edittoggle').on('change', function(event, data) {
event.stopPropagation();
var editable = $(this).is(':checked');
if (editable) {
jQuery('#matharray1').trigger('setmode', 'edit');
} else {
jQuery('#matharray1').trigger('setmode', 'view');
}
});
jQuery('#debugshowhide').on('click', function(event){
event.stopPropagation();
jQuery(this).closest('.debugarea').toggleClass('hidden');
})
var madata;
try {
madata = JSON.parse(localStorage.getItem('matharraydata'));
} catch (err) {}
if (!madata) {
madata = {
"type": "matharray",
"metadata": {
"creator": "",
"created": "",
"modifier": "demouser",
"modified": "2016-11-12T15:23:58.283Z",
"tags": [],
"lang": "en"
},
"data": {
"eqnarray": [
{
"left": "3x+4",
"middle": "=",
"right": "5x-1",
"description": "add $-5x-4$ on both sides"
},
{
"left": "3x-5x",
"middle": "=",
"right": "-1-4",
"description": "add compatible terms together"
},
{
"left": "-2x",
"middle": "=",
"right": "-5",
"description": "divide both sides by $-2$"
},
{
"left": "x",
"middle": "=",
"right": "\\frac{5}{2}",
"description": ""
}
]
}
}
};
madata.settings = {username: 'demouser', mode: (jQuery('#edittoggle').is(':checked') ? 'edit' : 'view')};
jQuery('#matharray1').matharray(madata);
jQuery('#matharray-data').val(JSON.stringify(madata, null, 4));
jQuery('#mathpanel').mqmathpanel();
})
</script>
</head>
<body>
<header>
<h1>Matharray</h1>
<h2>Interactive equationarrays for web.</h2>
</header>
<article>
<h1>Matharray</h1>
<p>
With Matharray you can write and show mathematical calculations and proofs in the format of <em>equationarray</em>.
Equationarray has multiple rows with consecutive equations aligned around equality sign (=) or some other relation.
In Matharray each row has three mathfields for the equation: <em>left-hand side</em>, <em>relation</em> and <em>right-hand side</em>.
Additionally each row has a textfield for a <em>comment or justification</em> of the step. Documentation of each step helps readers to
understand the reasoning.
</p>
<p>
In <em>view mode</em> the Matharray is read-only and in <em>edit mode</em> you can write in Matharray. In math mode
the editing cursor is shown in blue color and in text mode it is show in red. In math mode you can write
most LaTeX-commands and in text mode you can start math mode with $-key. When editing, following
keyboad actions can be used:
</p>
<p>
<label><input id="edittoggle" type="checkbox" checked> Edit mode</label> <em class="helper">← click the checkbox to switch between edit and view modes</em>
</p>
<div id="matharray1"></div>
<div class="debugarea hidden">
<p><button id="debugshowhide">Show/hide the data of the Matharray as JSON</button></p>
<textarea id="matharray-data"></textarea>
</div>
<section class="helpbox">
<h2>Writing math</h2>
<h3>MathQuill</h3>
<p>
Matharray uses <a href="http://mathquill.com">MathQuill</a>-library for math input.
With MathQuill simple math, numbers, letters, plus, minus and parenthesis can be just written as you would expect.
Multiplication sign <em>⋅</em> can be written with <em>*</em>-symbol and division/factions are written with <em>/</em>,
which automatically creates numerator and denominator. <strong>Try it!</strong>. Exponent is written with <em>^</em>-symbol.
(In Linux, you might want to tap that symbol twice to get exponent.)
</p>
<h3>LaTeX</h3>
<p>
More advanced math can be written in <a href="https://en.wikipedia.org/wiki/LaTeX">LaTeX</a>-syntax with commands starting
with <em>\</em>-character (<em>backslash</em>). For example the square root is written as <em>\sqrt</em> followed by space.
In Matharray, however, MathQuill is configured so that some of the most common commands and symbols can be written without the beginning
backslash.
These are: <em>alpha, beta, gamma, delta, pi, theta, sqrt, sum, binom, choose, sin, cos, tan, arcsin, arccos, arctan, log, ln</em> and <em>lg</em>.
</p>
<h3>Mathpanel</h3>
<p>
Together with the <em>Matharray</em> there is also <em>Mathpanel</em> which gives a button panel for inputting mathematical symbols and commands
in Matharray just by clicking the symbol with mouse. The panel is transprently shown, when a Mathquill field has focus and it is fully visible, when
mouse is over it. Symbols are organized in several tabs: <em>basic</em>, <em>relations</em>, <em>arrows</em>,
<em>numbersets</em>, <em>greek alphabets</em>, <em>brackets and parenthesis</em>, <em>functions</em>, <em>dots</em>, <em>sums and products</em>,
<em>logic</em>, <em>sets</em> and <em>other symbols</em>.
</p>
<h3>Navigation</h3>
<p>For editing following keys and key combinations can be used:</p>
<dl>
<dt>Arrows</dt>
<dd>With arrows the cursor and focus moves in the Matharray. Left and right arrows move the cursor in the text and when
either end of the field is reached, the cursor moves to the next or to the previous field. Up and down arrows make
the cursor move inside two-dimensional math formulas or between rows of the Matharray</dd>
<dt>Tab</dt>
<dd>With tabulator key you can jump to the next field and with Shift+tab to the previous field.</dd>
<dt>Enter</dt>
<dd>With enter key you can also jump to the next field. If the current field is the last field on the last row, a new empty row is
created and the focus moves to the first field on that row.</dd>
<dt>Ctrl+enter</dt>
<dd>Add a new empty row after current row.</dd>
<dt>Shift+enter</dt>
<dd>Add a copy of current row after current row. Math fields are copied, comment field is left empty. This is useful for example, when solving a
complex equation and you don't want to rewrite everything on every row.</dd>
<dt>Ctrl+backspace</dt>
<dd>Remove current row.</dd>
</dl>
</section>
<section>
<h2>For programmers</h2>
<h3>Matharray</h3>
<p>
The Matharray is written as a <a href="http://jquery.com/">jQuery</a>-plugin. If you want to create a matharry, then first create some HTML-element:
</p>
<pre>
<div id="placeformath"></div>
</pre>
<p>
Then init it as Matharray:
</p>
<pre>
$('#placeformath').matharray(data);
</pre>
<p>The data that is given to the plugin is a JavaScript-object of format:</p>
<pre>
{
"type": "matharray",
"metadata": {...},
"data": {...},
"settings": {
"username": "demouser",
"mode": "edit"
}
}
</pre>
<p>
If the data is not given, the plugin creates an empty Matharray in view mode. Available modes are <code>view</code> and <code>edit</code>.
</p>
<p>
The user / programmer can ask the plugin to give its data with:
</p>
<pre>
var data = $('#placeformath').matharray('getdata');
</pre>
<p>
The data is given in the same format. The <code>metadata</code>-attribute includes the information about the creator and modifier of the data
and the timestamps (unix millis) of creation and modification times.
</p>
<p>
The data can also be gotten by triggering the jQuery-object of the HTML-element a <code>getdata</code> jQuery-event and reading the data object
with key <code>[[elementdata]]</code> from jQuery-object's <code>.data()</code>.
</p>
<pre>
$('#placeformath').trigger('getdata');
var data = $('#placeformath').data('[[elementdata]]');
</pre>
<p>
The data of Matharray can also be obtained as an array of rows, which themselves are given as an array of strings, as follows:
</p>
<pre>
var data = $('#placeformath').matharray('latexarray');
</pre>
<p>
In this case the data is of following format:
</p>
<pre>
[
[
"3x+4",
"=",
"5x-1",
"add $-5x-4$ on both sides"
],
[
"3x-5x",
"=",
"-1-4",
"add compatible terms together"
],
[
"-2x",
"=",
"-5",
"divide by $-2$ on both sides"
],
[
"x",
"=",
"\\frac{5}{2}",
""
]
]
</pre>
<h3>Mathpanel</h3>
<p>
The Mathpanel is also implemented as a jQuery-plugin. It is drawn in its own HTML-element the same way as the Matharray:
</p>
<pre>
<div id="mathpanel"></div>
</pre>
<pre>
$('#mathpanel').mathpanel();
</pre>
<p>
When the Mathpanel is inited, it is shown whenever some MathQuill-field gets focus. The Mathpanel is shown under
the focused field as transparent so that it is not hiding text under it. The panel becomes fully visible, when
the mouse goes over it.
</p>
<p>
By default the Mathpanel has fixed selection of symbols and commands, but the user / programmer can override or extend
the set by giving it more buttons as a JavaScript object. You can see the source code of default panel in the file
<code>jquery.mathpanel.js</code> for the format.
</p>
<h3>Mathquill</h3>
<p>
In this example we have used a lightly patched version of the <a href="https://github.com/pesasa/mathquill/tree/matharray">MathQuill</a> (matharray-branch).
The Matharray works mostly also with the official version of the <a href="https://github.com/mathquill/mathquill">MathQuill</a>.
Main differences are in the behavior of the textfield (justifications). Namely navigation in textfields and copying and pasting of text.
Another improvement in our version is workin versions of the symbols of numbersets.
</p>
<h3>Licenses</h3>
<p>Required components are all free and open source:</p>
<ul>
<li><a href="http://jquery.com/">jQuery</a> (<a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, v.2.0</a>)</li>
<li><a href="http://mathquill.com/">MathQuill</a> (<a href="http://mozilla.org/MPL/2.0/">Mozilla Public License, v.2.0</a>)</li>
<li><a href="http://github.com/pesasa/matharray/">Matharray</a> (<a href="https://opensource.org/licenses/MIT">MIT License</a>)</li>
<li><a href="http://github.com/pesasa/matharray/">Mathpanel</a> (<a href="https://opensource.org/licenses/MIT">MIT License</a>)</li>
</ul>
</section>
</article>
<div id="mathpanel"></div>
<a href="https://github.com/pesasa/matharray"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
</body>
</html>