Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion testsuite/tests/input/tex/Base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12191,7 +12191,7 @@ describe('Character Class Changes', () => {

/********************************************************************************/

it('Mathop No Apply', () => {
it('Mathop No Apply I', () => {
toXmlMatch(
tex2mml('\\mathop{} x'),
`<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\mathop{} x" display="block">
Expand All @@ -12203,6 +12203,21 @@ describe('Character Class Changes', () => {

/********************************************************************************/

it('Mathop no Apply II', () => {
toXmlMatch(
tex2mml('\\mathop{\\mathrm{}{}} x'),
`<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\mathop{\\mathrm{}{}} x" display="block">
<mrow data-mjx-texclass="OP" data-latex="\\mathop{\\mathrm{}{}}">
<mrow data-mjx-texclass="ORD" data-latex="\\mathrm{}"></mrow>
<mrow data-mjx-texclass="ORD" data-latex="{}"></mrow>
</mrow>
<mi data-latex="x">x</mi>
</math>`
);
});

/********************************************************************************/

it('Mathrel', () => {
toXmlMatch(
tex2mml('\\mathrel{R}'),
Expand Down
30 changes: 30 additions & 0 deletions ts/core/MmlTree/MmlNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface MmlNode extends Node<MmlNode, MmlNodeClass> {
readonly isSpacelike: boolean;
readonly linebreakContainer: boolean;
readonly linebreakAlign: string;
readonly isEmpty: boolean;

/**
* The expected number of children (-1 means use inferred mrow)
Expand Down Expand Up @@ -540,6 +541,16 @@ export abstract class AbstractMmlNode
return 'data-align';
}

/**
* @returns {string} True if all child nodes are empty
*/
public get isEmpty(): boolean {
for (const child of this.childNodes) {
if (!child.isEmpty) return false;
}
return true;
}

/**
* @returns {number} The number of children allowed, or Infinity for any number,
* or -1 for when an inferred row is needed for the children.
Expand Down Expand Up @@ -1023,6 +1034,18 @@ export abstract class AbstractMmlTokenNode extends AbstractMmlNode {
return true;
}

/**
* @override
*/
public get isEmpty() {
for (const child of this.childNodes) {
if (!(child instanceof TextNode) || child.getText().length) {
return false;
}
}
return true;
}

/**
* Get the text of the token node (skipping mglyphs, and combining
* multiple text nodes)
Expand Down Expand Up @@ -1228,6 +1251,13 @@ export abstract class AbstractMmlEmptyNode
return false;
}

/**
* @returns {boolean} Is empty
*/
public get isEmpty(): boolean {
return true;
}

/**
* @returns {boolean} Not embellished
*/
Expand Down
2 changes: 1 addition & 1 deletion ts/input/tex/base/BaseItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ export class FnItem extends BaseItem {
}
}
// @test Mathop Apply, Mathop No Apply
if (top.isKind('TeXAtom') && top.childNodes[0].childNodes.length === 0) {
if (top.isKind('TeXAtom') && top.isEmpty) {
return [[top, item], true];
}
// @test Named Function, Named Function Arg
Expand Down
2 changes: 1 addition & 1 deletion ts/input/tex/mathtools/MathtoolsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const MathtoolsUtil = {
parser.stack.env,
parser.configuration
).mml();
return mml.isKind('TeXAtom') && mml.childNodes[0].childNodes.length === 0
return mml.isKind('TeXAtom') && mml.isEmpty
? parser.create('node', 'none')
: mml;
},
Expand Down