Skip to content
Open
19 changes: 17 additions & 2 deletions src/commands/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,23 @@ class MathBlock extends MathElement {
}
chToCmd(ch: string, options: CursorOptions) {
var cons;
// exclude f because it gets a dedicated command with more spacing
if (ch.match(/^[a-eg-zA-Z]$/)) return new Letter(ch);
// extract customCharacters early so we can easily default it to 'f'
var customCharacters = options?.customCharacters ?? 'f';
if (
customCharacters.indexOf(ch) >= 0 &&
(cons = (CharCmds as CharCmdsAny)[ch] || (LatexCmds as LatexCmdsAny)[ch])
) {
if (cons.constructor) {
return new cons(ch);
} else {
return cons(ch);
}
} else if (
// the patch to exclude 'f' from this regex is no longer needed since we
// usecustomCharacters
ch.match(/^[a-zA-Z]$/)
)
return new Letter(ch);
else if (/^\d$/.test(ch)) return new Digit(ch);
else if (options && options.typingSlashWritesDivisionSymbol && ch === '/')
return (LatexCmds as LatexCmdsSingleCharBuilder)['÷'](ch);
Expand Down
8 changes: 4 additions & 4 deletions src/commands/math/advancedSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,12 @@ LatexCmds.closecurlybrace = LatexCmds.rbrace = bindVanillaSymbol(
'}',
'right brace'
);
LatexCmds.lbrack = bindVanillaSymbol('[', 'left bracket');
LatexCmds.rbrack = bindVanillaSymbol(']', 'right bracket');
LatexCmds.lbrack = bindVanillaSymbol('[', '[', 'left bracket');
LatexCmds.rbrack = bindVanillaSymbol(']', ']', 'right bracket');

//various symbols
LatexCmds.slash = bindVanillaSymbol('/', 'slash');
LatexCmds.vert = bindVanillaSymbol('|', 'vertical bar');
LatexCmds.slash = bindVanillaSymbol('/', '/', 'slash');
LatexCmds.vert = bindVanillaSymbol('|', '|', 'vertical bar');
LatexCmds.perp = LatexCmds.perpendicular = bindVanillaSymbol(
'\\perp ',
'⊥',
Expand Down
2 changes: 1 addition & 1 deletion src/commands/math/basicSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ function defaultAutoOpNames() {
_maxLength: 9,
};
var mostOps = (
'arg deg det dim exp gcd hom inf ker lg lim ln log max min sup' +
'arg deg det dim exp gcd hom inf ker lg ln log max min sup' +
' limsup liminf injlim projlim Pr'
).split(' ');
for (var i = 0; i < mostOps.length; i += 1) {
Expand Down
47 changes: 43 additions & 4 deletions src/commands/math/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,9 @@ var LiveFraction =
leftward._groupingClass === 'mq-ellipsis-end') ||
leftward instanceof (LatexCmds.text || noop) ||
leftward instanceof SummationNotation ||
leftward instanceof Limit ||
leftward.ctrlSeq === '\\ ' ||
leftward.ctrlSeq === '&' ||
/^[,;:]$/.test(leftward.ctrlSeq as string)
) //lookbehind for operator
)
Expand Down Expand Up @@ -1616,7 +1618,9 @@ LatexCmds.left = class extends MathCommand {
var optWhitespace = Parser.optWhitespace;

return optWhitespace
.then(regex(/^(?:[([|]|\\\{|\\langle(?![a-zA-Z])|\\lVert(?![a-zA-Z]))/))
.then(
regex(/^(?:[([|]|\\\{|\\(?:lfloor|lceil|langle|lVert)(?![a-zA-z]))/)
)
.then(function (ctrlSeq) {
var open = ctrlSeq.replace(/^\\/, '');
if (ctrlSeq == '\\langle') {
Expand All @@ -1630,9 +1634,7 @@ LatexCmds.left = class extends MathCommand {
return latexMathParser.then(function (block) {
return string('\\right')
.skip(optWhitespace)
.then(
regex(/^(?:[\])|]|\\\}|\\rangle(?![a-zA-Z])|\\rVert(?![a-zA-Z]))/)
)
.then(regex(/^(?:[\])|]|\\\}|\\[a-zA-z]+)/))
.map(function (end) {
var close = end.replace(/^\\/, '');
if (end == '\\rangle') {
Expand Down Expand Up @@ -1869,3 +1871,40 @@ class EmbedNode extends MQSymbol {
}
}
LatexCmds.embed = EmbedNode;
class Limit extends MathCommand {
constructor(ctrlSeq?: string, domView?: DOMView, textTemplate?: string[]) {
super(ctrlSeq, domView, textTemplate);
this.ctrlSeq = '\\lim';
this.domView = new DOMView(1, function (blocks) {
return h('span', { class: 'mq-limit mq-non-leaf' }, [
h('span', { class: 'mq-limit-label' }, [h.text('lim')]),
h.block('span', { class: 'mq-limit-sub mq-non-leaf' }, blocks[0]),
]);
});
this.textTemplate = ['lim(', ')'];
this.mathspeakTemplate = ['Limit', 'EndLimit'];
}

override latexRecursive(ctx: LatexContext) {
this.checkCursorContextOpen(ctx);
ctx.latex += '\\lim_{';
this.getEnd(L).latexRecursive(ctx);
ctx.latex += '}';
this.checkCursorContextClose(ctx);
}

override parser() {
return Parser.string('_')
.then(function () {
return latexMathParser;
})
.map(function (block) {
const limit = new Limit('\\lim', undefined!, undefined!);
limit.blocks = [block];
block.adopt(limit, 0, 0);
return limit;
})
.or(super.parser());
}
}
LatexCmds.limit = LatexCmds.lim = Limit;
Loading