Skip to content

Commit caa85a3

Browse files
authored
Merge pull request #40 from drgrice1/parentheses-issues
Add some more cases where parentheses are needed in text output.
2 parents 629bef0 + f5b14c5 commit caa85a3

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@openwebwork/mathquill",
33
"description": "Easily type math in your webapp",
4-
"version": "0.11.0",
4+
"version": "0.11.1",
55
"license": "MPL-2.0",
66
"repository": {
77
"type": "git",

src/commands/math/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ const FractionChooseCreateLeftOfMixin = <TBase extends Constructor<MathCommand>>
305305
while (
306306
leftward &&
307307
!(
308-
leftward instanceof BinaryOperator ||
308+
(leftward instanceof BinaryOperator && !(leftward instanceof LatexCmds.factorial)) ||
309309
('text' in LatexCmds && leftward instanceof LatexCmds.text) ||
310310
leftward instanceof UpperLowerLimitCommand ||
311311
leftward.ctrlSeq === '\\ ' ||

src/commands/mathElements.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,13 @@ export class Fraction extends MathCommand {
716716
let numBlocks = 0;
717717
let haveDigits = false;
718718
let numPeriods = 0;
719+
let newBlock = false;
719720
this.ends[dir]?.eachChild((child: TNode) => {
720721
if (child instanceof Digit) haveDigits = true;
721722
if (child instanceof VanillaSymbol && child.ctrlSeq === '.') ++numPeriods;
722723

723724
if (
725+
newBlock ||
724726
!(
725727
child instanceof Digit ||
726728
(child instanceof VanillaSymbol && child.ctrlSeq === '.' && numPeriods < 2 && !numBlocks) ||
@@ -730,6 +732,11 @@ export class Fraction extends MathCommand {
730732
)
731733
++numBlocks;
732734

735+
// These are things that terminate a block. Anything typed after them
736+
// starts a new block and increments the block count above.
737+
newBlock =
738+
('factorial' in LatexCmds && child instanceof LatexCmds.factorial) || child instanceof SupSub;
739+
733740
if (
734741
(haveDigits && numBlocks) ||
735742
numBlocks > 1 ||
@@ -838,11 +845,13 @@ export const supSubText = (prefix: string, block?: TNode) => {
838845
let numBlocks = 0;
839846
let haveDigits = false;
840847
let numPeriods = 0;
848+
let newBlock = false;
841849
block?.eachChild((child: TNode) => {
842850
if (child instanceof Digit) haveDigits = true;
843851
if (child instanceof VanillaSymbol && child.ctrlSeq === '.') ++numPeriods;
844852

845853
if (
854+
newBlock ||
846855
!(
847856
child instanceof Digit ||
848857
(child instanceof VanillaSymbol && child.ctrlSeq === '.' && numPeriods < 2 && !numBlocks) ||
@@ -851,6 +860,10 @@ export const supSubText = (prefix: string, block?: TNode) => {
851860
)
852861
++numBlocks;
853862

863+
// These are things that terminate a block. Anything typed after them
864+
// starts a new block and increments the block count above.
865+
newBlock = 'factorial' in LatexCmds && child instanceof LatexCmds.factorial;
866+
854867
if (
855868
(haveDigits && numBlocks) ||
856869
numBlocks > 1 ||

0 commit comments

Comments
 (0)