@@ -4187,7 +4187,12 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
4187
4187
return REVERSE_MATH_SYMBOLS[s] || s;
4188
4188
}
4189
4189
if (parseMode === 'text') {
4190
- return (Object.keys(TEXT_SYMBOLS).find((x) => TEXT_SYMBOLS[x] === s) || s);
4190
+ let textSymbol = Object.keys(TEXT_SYMBOLS).find((x) => TEXT_SYMBOLS[x] === s);
4191
+ if (!textSymbol) {
4192
+ const hex = s.codePointAt(0).toString(16);
4193
+ textSymbol = '^'.repeat(hex.length) + hex;
4194
+ }
4195
+ return textSymbol;
4191
4196
}
4192
4197
return s;
4193
4198
}
@@ -4439,12 +4444,12 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
4439
4444
}
4440
4445
return result;
4441
4446
}
4442
- function getValue(mode, symbol) {
4447
+ /**
4448
+ * Gets the value of a symbol in math mode
4449
+ */
4450
+ function getValue(symbol) {
4443
4451
var _a, _b;
4444
- if (mode === 'math') {
4445
- return (_b = (_a = MATH_SYMBOLS[symbol]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : symbol;
4446
- }
4447
- return TEXT_SYMBOLS[symbol] ? TEXT_SYMBOLS[symbol] : symbol;
4452
+ return (_b = (_a = MATH_SYMBOLS[symbol]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : symbol;
4448
4453
}
4449
4454
function emit(symbol, parent, atom, emitFn) {
4450
4455
var _a, _b, _c;
@@ -4459,8 +4464,9 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
4459
4464
if (atom.body && ((_c = (_b = FUNCTIONS[symbol]) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.length) === 1) {
4460
4465
return symbol + '{' + emitFn(atom, atom.body) + '}';
4461
4466
}
4462
- // No custom emit function provided, return the symbol (could be a character)
4463
- return symbol;
4467
+ // No custom emit function provided, return an escaped version of the symbol
4468
+ const hex = symbol.codePointAt(0).toString(16);
4469
+ return '^'.repeat(hex.length) + hex;
4464
4470
}
4465
4471
function getEnvironmentDefinition(name) {
4466
4472
var _a;
@@ -4541,6 +4547,9 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
4541
4547
else if (TEXT_SYMBOLS[symbol]) {
4542
4548
info = { value: TEXT_SYMBOLS[symbol] };
4543
4549
}
4550
+ else if (parseMode === 'text') {
4551
+ info = { value: symbol };
4552
+ }
4544
4553
}
4545
4554
// Special case `f`, `g` and `h` are recognized as functions.
4546
4555
if (info &&
@@ -5435,6 +5444,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
5435
5444
'cotg',
5436
5445
'csc',
5437
5446
'cosec',
5447
+ 'cis',
5438
5448
'deg',
5439
5449
'dim',
5440
5450
'exp',
@@ -7310,7 +7320,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
7310
7320
* scriptscriptstyle.
7311
7321
*/
7312
7322
function makeSmallDelim(type, delim, style, center, context, classes = '') {
7313
- const text = makeSymbol('Main-Regular', getValue('math', delim));
7323
+ const text = makeSymbol('Main-Regular', getValue(delim));
7314
7324
const span = makeStyleWrap(type, text, context.mathstyle, style, classes);
7315
7325
if (center) {
7316
7326
span.setTop((1 - context.mathstyle.sizeMultiplier / style.sizeMultiplier) *
@@ -7327,7 +7337,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
7327
7337
* Size3, or Size4 fonts. It is always rendered in textstyle.
7328
7338
*/
7329
7339
function makeLargeDelim(type, delim, size, center, context, classes = '') {
7330
- const result = makeStyleWrap(type, makeSymbol('Size' + size + '-Regular', getValue('math', delim), 'delimsizing size' + size), context.mathstyle, MATHSTYLES.textstyle, classes);
7340
+ const result = makeStyleWrap(type, makeSymbol('Size' + size + '-Regular', getValue(delim), 'delimsizing size' + size), context.mathstyle, MATHSTYLES.textstyle, classes);
7331
7341
if (center) {
7332
7342
result.setTop((1 - context.mathstyle.sizeMultiplier) *
7333
7343
context.mathstyle.metrics.axisHeight);
@@ -7351,7 +7361,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
7351
7361
else if (font === 'Size4-Regular') {
7352
7362
sizeClass = ' delim-size4';
7353
7363
}
7354
- return makeSymbol(font, getValue('math', symbol), 'delimsizinginner' + sizeClass);
7364
+ return makeSymbol(font, getValue(symbol), 'delimsizinginner' + sizeClass);
7355
7365
}
7356
7366
/**
7357
7367
* Make a stacked delimiter out of a given delimiter, with the total height at
@@ -7364,7 +7374,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
7364
7374
let middle;
7365
7375
let repeat;
7366
7376
let bottom;
7367
- top = repeat = bottom = getValue('math', delim);
7377
+ top = repeat = bottom = getValue(delim);
7368
7378
middle = null;
7369
7379
// Also keep track of what font the delimiters are in
7370
7380
let font = 'Size1-Regular';
@@ -7512,16 +7522,16 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
7512
7522
repeat = top = ' ';
7513
7523
}
7514
7524
// Get the metrics of the four sections
7515
- const topMetrics = getCharacterMetrics(getValue('math', top), font);
7525
+ const topMetrics = getCharacterMetrics(getValue(top), font);
7516
7526
const topHeightTotal = topMetrics.height + topMetrics.depth;
7517
- const repeatMetrics = getCharacterMetrics(getValue('math', repeat), font);
7527
+ const repeatMetrics = getCharacterMetrics(getValue(repeat), font);
7518
7528
const repeatHeightTotal = repeatMetrics.height + repeatMetrics.depth;
7519
- const bottomMetrics = getCharacterMetrics(getValue('math', bottom), font);
7529
+ const bottomMetrics = getCharacterMetrics(getValue(bottom), font);
7520
7530
const bottomHeightTotal = bottomMetrics.height + bottomMetrics.depth;
7521
7531
let middleHeightTotal = 0;
7522
7532
let middleFactor = 1;
7523
7533
if (middle !== null) {
7524
- const middleMetrics = getCharacterMetrics(getValue('math', middle), font);
7534
+ const middleMetrics = getCharacterMetrics(getValue(middle), font);
7525
7535
middleHeightTotal = middleMetrics.height + middleMetrics.depth;
7526
7536
middleFactor = 2; // repeat symmetrically above and below middle
7527
7537
}
@@ -7765,7 +7775,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
7765
7775
sequence = stackAlwaysDelimiterSequence;
7766
7776
}
7767
7777
// Look through the sequence
7768
- const delimType = traverseSequence(getValue('math', delim), height, sequence, context);
7778
+ const delimType = traverseSequence(getValue(delim), height, sequence, context);
7769
7779
// Depending on the sequence element we decided on,
7770
7780
// call the appropriate function.
7771
7781
if (delimType.type === 'small') {
@@ -9302,14 +9312,10 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
9302
9312
if (this.peek() === '^') {
9303
9313
// It might be a ^^ command (inline hex character)
9304
9314
this.get();
9305
- let hex = this.match(/^\^\^[0-9a-f][0-9a-f][0-9a-f][0-9a-f]/);
9315
+ // There can be zero to six carets with the same number of hex digits
9316
+ const hex = this.match(/^(\^(\^(\^(\^[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f][0-9a-f]/);
9306
9317
if (hex) {
9307
- // It's a ^^^^ hex char
9308
- return String.fromCodePoint(parseInt(hex.slice(2), 16));
9309
- }
9310
- hex = this.match(/^[0-9a-f][0-9a-f]/);
9311
- if (hex) {
9312
- return String.fromCodePoint(parseInt(hex, 16));
9318
+ return String.fromCodePoint(parseInt(hex.slice(hex.lastIndexOf('^') + 1), 16));
9313
9319
}
9314
9320
}
9315
9321
return next;
@@ -11333,7 +11339,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
11333
11339
// there isn't a valid delimiter after `\right`, we'll
11334
11340
// consider the `\right` missing and set the `rightDelim` to undefined
11335
11341
const rightDelim = this.scanDelim();
11336
- const result = new Atom(this.parseMode, 'leftright');
11342
+ const result = new Atom(this.parseMode, 'leftright', '', this.style );
11337
11343
result.leftDelim = leftDelim;
11338
11344
result.rightDelim = rightDelim !== null && rightDelim !== void 0 ? rightDelim : undefined;
11339
11345
result.inner = close === 'right';
@@ -11882,7 +11888,8 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
11882
11888
const atom = new Atom(this.parseMode, 'group', parseString(def, this.parseMode, args, this.macros, false, this.onError));
11883
11889
atom.captureSelection = true;
11884
11890
atom.symbol = macro;
11885
- atom.latex = macro + tokensToString(this.tokens.slice(initialIndex));
11891
+ atom.latex =
11892
+ macro + tokensToString(this.tokens.slice(initialIndex, this.index));
11886
11893
return atom;
11887
11894
}
11888
11895
/**
@@ -14830,8 +14837,8 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
14830
14837
ifMode: 'text',
14831
14838
command: 'moveToPreviousPlaceholder',
14832
14839
},
14833
- { key: '[Escape]', ifMode: 'math', command: ['switch-mode ', 'command'] },
14834
- { key: '\\', ifMode: 'math', command: ['switch-mode ', 'command'] },
14840
+ { key: '[Escape]', ifMode: 'math', command: ['switchMode ', 'command'] },
14841
+ { key: '\\', ifMode: 'math', command: ['switchMode ', 'command'] },
14835
14842
{
14836
14843
key: 'alt+[Equal]',
14837
14844
ifMode: 'math',
@@ -14928,7 +14935,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
14928
14935
{
14929
14936
key: 'shift+[Quote]',
14930
14937
ifMode: 'text',
14931
- command: ['switch-mode ', 'math', '”', ''],
14938
+ command: ['switchMode ', 'math', '”', ''],
14932
14939
},
14933
14940
// WOLFRAM MATHEMATICA BINDINGS
14934
14941
{
@@ -17288,7 +17295,9 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
17288
17295
selector = selector.replace(/-\w/g, (m) => m[1].toUpperCase());
17289
17296
if (((_a = COMMANDS[selector]) === null || _a === void 0 ? void 0 : _a.target) === 'model') {
17290
17297
if (/^(delete|transpose|add)/.test(selector)) {
17291
- mathfield.resetKeystrokeBuffer();
17298
+ if (selector !== 'deletePreviousChar') {
17299
+ mathfield.resetKeystrokeBuffer();
17300
+ }
17292
17301
}
17293
17302
if (/^(delete|transpose|add)/.test(selector) &&
17294
17303
mathfield.mode !== 'command') {
@@ -17883,6 +17892,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
17883
17892
sec: { mode: 'math', value: '\\sec' },
17884
17893
csc: { mode: 'math', value: '\\csc' },
17885
17894
cot: { mode: 'math', value: '\\cot' },
17895
+ cis: { mode: 'math', value: '\\cis' },
17886
17896
log: { mode: 'math', value: '\\log' },
17887
17897
ln: { mode: 'math', value: '\\ln' },
17888
17898
exp: { mode: 'math', value: '\\exp' },
@@ -22000,7 +22010,18 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
22000
22010
// see 5.3)
22001
22011
if (mathfield.mode !== 'command' &&
22002
22012
(!evt || (!evt.ctrlKey && !evt.metaKey))) {
22003
- if (!mightProducePrintableCharacter(evt)) {
22013
+ if (keystroke === '[Backspace]') {
22014
+ // Special case for backspace
22015
+ mathfield.keystrokeBuffer = mathfield.keystrokeBuffer.slice(0, -1);
22016
+ mathfield.keystrokeBufferStates.push(mathfield.getUndoRecord());
22017
+ if (mathfield.config.inlineShortcutTimeout) {
22018
+ // Set a timer to reset the shortcut buffer
22019
+ mathfield.keystrokeBufferResetTimer = setTimeout(() => {
22020
+ mathfield.resetKeystrokeBuffer();
22021
+ }, mathfield.config.inlineShortcutTimeout);
22022
+ }
22023
+ }
22024
+ else if (!mightProducePrintableCharacter(evt)) {
22004
22025
// It was a non-alpha character (PageUp, End, etc...)
22005
22026
mathfield.resetKeystrokeBuffer();
22006
22027
}
@@ -26017,7 +26038,15 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
26017
26038
[atoms, tokens] = options.parse('text', tokens, options);
26018
26039
result = [...result, ...atoms];
26019
26040
}
26020
- else if (token.length === 1) {
26041
+ else if (token === '<$>' || token === '<$$>') {
26042
+ // Mode-shift
26043
+ const subtokens = tokens.slice(0, tokens.findIndex((x) => x === token));
26044
+ tokens = tokens.slice(subtokens.length + 1);
26045
+ const [atoms] = options.parse('math', subtokens, options);
26046
+ result = [...result, ...atoms];
26047
+ }
26048
+ else if (token === '<{>' || token === '<}>') ;
26049
+ else {
26021
26050
const info = getInfo(token, 'text', options.macros);
26022
26051
if (!info) {
26023
26052
error({ code: 'unexpected-token' });
@@ -26033,20 +26062,6 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
26033
26062
error({ code: 'unexpected-token' });
26034
26063
}
26035
26064
}
26036
- else if (token === '<$>' || token === '<$$>') {
26037
- // Mode-shift
26038
- const subtokens = tokens.slice(0, tokens.findIndex((x) => x === token));
26039
- tokens = tokens.slice(subtokens.length + 1);
26040
- const [atoms] = options.parse('math', subtokens, options);
26041
- result = [...result, ...atoms];
26042
- }
26043
- else if (token === '<{>' || token === '<}>') ;
26044
- else {
26045
- error({
26046
- code: 'unexpected-token',
26047
- arg: token,
26048
- });
26049
- }
26050
26065
}
26051
26066
return [result, tokens];
26052
26067
}
@@ -30930,6 +30945,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
30930
30945
'\\tanh': 'Tanh',
30931
30946
'\\tg': 'Tan',
30932
30947
'\\th': 'Tanh',
30948
+ '\\cis': 'Cis',
30933
30949
}[latex]) !== null && _a !== void 0 ? _a : latex;
30934
30950
if (isInverse) {
30935
30951
head = [INVERSE_FUNCTION, head];
@@ -33354,6 +33370,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
33354
33370
csch: '\\csch %0',
33355
33371
sech: '\\sech %0',
33356
33372
coth: '\\coth %0',
33373
+ cis: '\\cis %0',
33357
33374
arcsin: '\\arcsin %0',
33358
33375
arccos: '\\arccos %0',
33359
33376
arctan: '\\arctan %0',
@@ -36215,6 +36232,20 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
36215
36232
$typedText(text) {
36216
36233
onTypedText(this, text);
36217
36234
}
36235
+ getCaretPosition() {
36236
+ const caretPosition = getCaretPosition(this.field);
36237
+ return caretPosition
36238
+ ? { x: caretPosition.x, y: caretPosition.y }
36239
+ : null;
36240
+ }
36241
+ setCaretPosition(x, y) {
36242
+ const oldPath = this.model.clone();
36243
+ const anchor = pathFromPoint(this, x, y, { bias: 0 });
36244
+ const result = setPath(this.model, anchor, 0);
36245
+ this.model.announce('move', oldPath);
36246
+ requestUpdate(this);
36247
+ return result;
36248
+ }
36218
36249
canUndo() {
36219
36250
return this.undoManager.canUndo();
36220
36251
}
@@ -37307,6 +37338,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
37307
37338
'\\tanh',
37308
37339
'\\tg',
37309
37340
'\\th',
37341
+ '\\cis',
37310
37342
], UNCOMMON);
37311
37343
metadata('Functions', ['\\ln', '\\log', '\\exp', '\\lim'], SUPERCOMMON);
37312
37344
metadata('Functions', ['\\dim', '\\ker', '\\deg', '\\det', '\\mod', '\\min', '\\max'], COMMON);
0 commit comments