Skip to content

Commit 99f9100

Browse files
committed
add cis
1 parent b1f80dd commit 99f9100

11 files changed

+176
-101
lines changed

dist/mathlive.js

Lines changed: 78 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,7 +4187,12 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
41874187
return REVERSE_MATH_SYMBOLS[s] || s;
41884188
}
41894189
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;
41914196
}
41924197
return s;
41934198
}
@@ -4439,12 +4444,12 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
44394444
}
44404445
return result;
44414446
}
4442-
function getValue(mode, symbol) {
4447+
/**
4448+
* Gets the value of a symbol in math mode
4449+
*/
4450+
function getValue(symbol) {
44434451
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;
44484453
}
44494454
function emit(symbol, parent, atom, emitFn) {
44504455
var _a, _b, _c;
@@ -4459,8 +4464,9 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
44594464
if (atom.body && ((_c = (_b = FUNCTIONS[symbol]) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.length) === 1) {
44604465
return symbol + '{' + emitFn(atom, atom.body) + '}';
44614466
}
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;
44644470
}
44654471
function getEnvironmentDefinition(name) {
44664472
var _a;
@@ -4541,6 +4547,9 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
45414547
else if (TEXT_SYMBOLS[symbol]) {
45424548
info = { value: TEXT_SYMBOLS[symbol] };
45434549
}
4550+
else if (parseMode === 'text') {
4551+
info = { value: symbol };
4552+
}
45444553
}
45454554
// Special case `f`, `g` and `h` are recognized as functions.
45464555
if (info &&
@@ -5435,6 +5444,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
54355444
'cotg',
54365445
'csc',
54375446
'cosec',
5447+
'cis',
54385448
'deg',
54395449
'dim',
54405450
'exp',
@@ -7310,7 +7320,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
73107320
* scriptscriptstyle.
73117321
*/
73127322
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));
73147324
const span = makeStyleWrap(type, text, context.mathstyle, style, classes);
73157325
if (center) {
73167326
span.setTop((1 - context.mathstyle.sizeMultiplier / style.sizeMultiplier) *
@@ -7327,7 +7337,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
73277337
* Size3, or Size4 fonts. It is always rendered in textstyle.
73287338
*/
73297339
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);
73317341
if (center) {
73327342
result.setTop((1 - context.mathstyle.sizeMultiplier) *
73337343
context.mathstyle.metrics.axisHeight);
@@ -7351,7 +7361,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
73517361
else if (font === 'Size4-Regular') {
73527362
sizeClass = ' delim-size4';
73537363
}
7354-
return makeSymbol(font, getValue('math', symbol), 'delimsizinginner' + sizeClass);
7364+
return makeSymbol(font, getValue(symbol), 'delimsizinginner' + sizeClass);
73557365
}
73567366
/**
73577367
* 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`,
73647374
let middle;
73657375
let repeat;
73667376
let bottom;
7367-
top = repeat = bottom = getValue('math', delim);
7377+
top = repeat = bottom = getValue(delim);
73687378
middle = null;
73697379
// Also keep track of what font the delimiters are in
73707380
let font = 'Size1-Regular';
@@ -7512,16 +7522,16 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
75127522
repeat = top = ' ';
75137523
}
75147524
// Get the metrics of the four sections
7515-
const topMetrics = getCharacterMetrics(getValue('math', top), font);
7525+
const topMetrics = getCharacterMetrics(getValue(top), font);
75167526
const topHeightTotal = topMetrics.height + topMetrics.depth;
7517-
const repeatMetrics = getCharacterMetrics(getValue('math', repeat), font);
7527+
const repeatMetrics = getCharacterMetrics(getValue(repeat), font);
75187528
const repeatHeightTotal = repeatMetrics.height + repeatMetrics.depth;
7519-
const bottomMetrics = getCharacterMetrics(getValue('math', bottom), font);
7529+
const bottomMetrics = getCharacterMetrics(getValue(bottom), font);
75207530
const bottomHeightTotal = bottomMetrics.height + bottomMetrics.depth;
75217531
let middleHeightTotal = 0;
75227532
let middleFactor = 1;
75237533
if (middle !== null) {
7524-
const middleMetrics = getCharacterMetrics(getValue('math', middle), font);
7534+
const middleMetrics = getCharacterMetrics(getValue(middle), font);
75257535
middleHeightTotal = middleMetrics.height + middleMetrics.depth;
75267536
middleFactor = 2; // repeat symmetrically above and below middle
75277537
}
@@ -7765,7 +7775,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
77657775
sequence = stackAlwaysDelimiterSequence;
77667776
}
77677777
// Look through the sequence
7768-
const delimType = traverseSequence(getValue('math', delim), height, sequence, context);
7778+
const delimType = traverseSequence(getValue(delim), height, sequence, context);
77697779
// Depending on the sequence element we decided on,
77707780
// call the appropriate function.
77717781
if (delimType.type === 'small') {
@@ -9302,14 +9312,10 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
93029312
if (this.peek() === '^') {
93039313
// It might be a ^^ command (inline hex character)
93049314
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]/);
93069317
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));
93139319
}
93149320
}
93159321
return next;
@@ -11333,7 +11339,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
1133311339
// there isn't a valid delimiter after `\right`, we'll
1133411340
// consider the `\right` missing and set the `rightDelim` to undefined
1133511341
const rightDelim = this.scanDelim();
11336-
const result = new Atom(this.parseMode, 'leftright');
11342+
const result = new Atom(this.parseMode, 'leftright', '', this.style);
1133711343
result.leftDelim = leftDelim;
1133811344
result.rightDelim = rightDelim !== null && rightDelim !== void 0 ? rightDelim : undefined;
1133911345
result.inner = close === 'right';
@@ -11882,7 +11888,8 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
1188211888
const atom = new Atom(this.parseMode, 'group', parseString(def, this.parseMode, args, this.macros, false, this.onError));
1188311889
atom.captureSelection = true;
1188411890
atom.symbol = macro;
11885-
atom.latex = macro + tokensToString(this.tokens.slice(initialIndex));
11891+
atom.latex =
11892+
macro + tokensToString(this.tokens.slice(initialIndex, this.index));
1188611893
return atom;
1188711894
}
1188811895
/**
@@ -14830,8 +14837,8 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
1483014837
ifMode: 'text',
1483114838
command: 'moveToPreviousPlaceholder',
1483214839
},
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'] },
1483514842
{
1483614843
key: 'alt+[Equal]',
1483714844
ifMode: 'math',
@@ -14928,7 +14935,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
1492814935
{
1492914936
key: 'shift+[Quote]',
1493014937
ifMode: 'text',
14931-
command: ['switch-mode', 'math', '”', ''],
14938+
command: ['switchMode', 'math', '”', ''],
1493214939
},
1493314940
// WOLFRAM MATHEMATICA BINDINGS
1493414941
{
@@ -17288,7 +17295,9 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
1728817295
selector = selector.replace(/-\w/g, (m) => m[1].toUpperCase());
1728917296
if (((_a = COMMANDS[selector]) === null || _a === void 0 ? void 0 : _a.target) === 'model') {
1729017297
if (/^(delete|transpose|add)/.test(selector)) {
17291-
mathfield.resetKeystrokeBuffer();
17298+
if (selector !== 'deletePreviousChar') {
17299+
mathfield.resetKeystrokeBuffer();
17300+
}
1729217301
}
1729317302
if (/^(delete|transpose|add)/.test(selector) &&
1729417303
mathfield.mode !== 'command') {
@@ -17883,6 +17892,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
1788317892
sec: { mode: 'math', value: '\\sec' },
1788417893
csc: { mode: 'math', value: '\\csc' },
1788517894
cot: { mode: 'math', value: '\\cot' },
17895+
cis: { mode: 'math', value: '\\cis' },
1788617896
log: { mode: 'math', value: '\\log' },
1788717897
ln: { mode: 'math', value: '\\ln' },
1788817898
exp: { mode: 'math', value: '\\exp' },
@@ -22000,7 +22010,18 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
2200022010
// see 5.3)
2200122011
if (mathfield.mode !== 'command' &&
2200222012
(!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)) {
2200422025
// It was a non-alpha character (PageUp, End, etc...)
2200522026
mathfield.resetKeystrokeBuffer();
2200622027
}
@@ -26017,7 +26038,15 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
2601726038
[atoms, tokens] = options.parse('text', tokens, options);
2601826039
result = [...result, ...atoms];
2601926040
}
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 {
2602126050
const info = getInfo(token, 'text', options.macros);
2602226051
if (!info) {
2602326052
error({ code: 'unexpected-token' });
@@ -26033,20 +26062,6 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
2603326062
error({ code: 'unexpected-token' });
2603426063
}
2603526064
}
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-
}
2605026065
}
2605126066
return [result, tokens];
2605226067
}
@@ -30930,6 +30945,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
3093030945
'\\tanh': 'Tanh',
3093130946
'\\tg': 'Tan',
3093230947
'\\th': 'Tanh',
30948+
'\\cis': 'Cis',
3093330949
}[latex]) !== null && _a !== void 0 ? _a : latex;
3093430950
if (isInverse) {
3093530951
head = [INVERSE_FUNCTION, head];
@@ -33354,6 +33370,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
3335433370
csch: '\\csch %0',
3335533371
sech: '\\sech %0',
3335633372
coth: '\\coth %0',
33373+
cis: '\\cis %0',
3335733374
arcsin: '\\arcsin %0',
3335833375
arccos: '\\arccos %0',
3335933376
arctan: '\\arctan %0',
@@ -36215,6 +36232,20 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
3621536232
$typedText(text) {
3621636233
onTypedText(this, text);
3621736234
}
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+
}
3621836249
canUndo() {
3621936250
return this.undoManager.canUndo();
3622036251
}
@@ -37307,6 +37338,7 @@ M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
3730737338
'\\tanh',
3730837339
'\\tg',
3730937340
'\\th',
37341+
'\\cis',
3731037342
], UNCOMMON);
3731137343
metadata('Functions', ['\\ln', '\\log', '\\exp', '\\lim'], SUPERCOMMON);
3731237344
metadata('Functions', ['\\dim', '\\ker', '\\deg', '\\det', '\\mod', '\\min', '\\max'], COMMON);

dist/mathlive.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mathlive.min.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)