diff --git a/package.json b/package.json index b1a46344..eac19864 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@openwebwork/mathquill", "description": "Easily type math in your webapp", - "version": "0.11.0", + "version": "0.11.1", "license": "MPL-2.0", "repository": { "type": "git", diff --git a/src/commands/math/commands.ts b/src/commands/math/commands.ts index 2efbe9c9..97d9148a 100644 --- a/src/commands/math/commands.ts +++ b/src/commands/math/commands.ts @@ -305,7 +305,7 @@ const FractionChooseCreateLeftOfMixin = > while ( leftward && !( - leftward instanceof BinaryOperator || + (leftward instanceof BinaryOperator && !(leftward instanceof LatexCmds.factorial)) || ('text' in LatexCmds && leftward instanceof LatexCmds.text) || leftward instanceof UpperLowerLimitCommand || leftward.ctrlSeq === '\\ ' || diff --git a/src/commands/mathElements.ts b/src/commands/mathElements.ts index 10d51466..91ae9b96 100644 --- a/src/commands/mathElements.ts +++ b/src/commands/mathElements.ts @@ -716,11 +716,13 @@ export class Fraction extends MathCommand { let numBlocks = 0; let haveDigits = false; let numPeriods = 0; + let newBlock = false; this.ends[dir]?.eachChild((child: TNode) => { if (child instanceof Digit) haveDigits = true; if (child instanceof VanillaSymbol && child.ctrlSeq === '.') ++numPeriods; if ( + newBlock || !( child instanceof Digit || (child instanceof VanillaSymbol && child.ctrlSeq === '.' && numPeriods < 2 && !numBlocks) || @@ -730,6 +732,11 @@ export class Fraction extends MathCommand { ) ++numBlocks; + // These are things that terminate a block. Anything typed after them + // starts a new block and increments the block count above. + newBlock = + ('factorial' in LatexCmds && child instanceof LatexCmds.factorial) || child instanceof SupSub; + if ( (haveDigits && numBlocks) || numBlocks > 1 || @@ -838,11 +845,13 @@ export const supSubText = (prefix: string, block?: TNode) => { let numBlocks = 0; let haveDigits = false; let numPeriods = 0; + let newBlock = false; block?.eachChild((child: TNode) => { if (child instanceof Digit) haveDigits = true; if (child instanceof VanillaSymbol && child.ctrlSeq === '.') ++numPeriods; if ( + newBlock || !( child instanceof Digit || (child instanceof VanillaSymbol && child.ctrlSeq === '.' && numPeriods < 2 && !numBlocks) || @@ -851,6 +860,10 @@ export const supSubText = (prefix: string, block?: TNode) => { ) ++numBlocks; + // These are things that terminate a block. Anything typed after them + // starts a new block and increments the block count above. + newBlock = 'factorial' in LatexCmds && child instanceof LatexCmds.factorial; + if ( (haveDigits && numBlocks) || numBlocks > 1 ||