Skip to content

Commit

Permalink
Merge pull request #1003 from mathjax/issue3098c
Browse files Browse the repository at this point in the history
Don't include extra linebreak positions after an explicit break.
  • Loading branch information
dpvc authored Sep 15, 2023
2 parents b9d7b93 + d653923 commit 55699fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ts/output/chtml/Wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ CommonWrapper<
*/
protected handleSpace() {
const adaptor = this.adaptor;
const breakable = !!this.node.getProperty('breakable');
const breakable = !!this.node.getProperty('breakable') && !this.node.getProperty('newline');
const n = this.dom.length - 1;
for (const data of [[this.getLineBBox(0).L, 'space', 'marginLeft', 0],
[this.getLineBBox(n).R, 'rspace', 'marginRight', n]]) {
Expand Down
40 changes: 26 additions & 14 deletions ts/output/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,14 @@ export abstract class CommonOutputJax<
public markInlineBreaks(node: MmlNode) {
if (!node) return;
const forcebreak = this.forceInlineBreaks;
let postbreak = false;
let marked = false;
let markNext = '';
for (const child of node.childNodes) {
if (markNext) {
marked = this.markInlineBreak(marked, forcebreak, markNext, node, child);
markNext = '';
postbreak = false;
} else if (child.isEmbellished) {
if (child === node.childNodes[0]) {
continue;
Expand All @@ -413,29 +415,36 @@ export abstract class CommonOutputJax<
(texClass === TEXCLASS.ORD && mo.hasSpacingAttributes()) ||
linebreak !== 'auto') && linebreak !== 'nobreak') {
if (linebreakstyle === 'before') {
marked = this.markInlineBreak(marked, forcebreak, linebreak, node, child, mo);
if (!postbreak || linebreak !== 'auto') {
marked = this.markInlineBreak(marked, forcebreak, linebreak, node, child, mo);
}
} else {
markNext = linebreak;
}
}
postbreak = (linebreak === 'newline' && linebreakstyle === 'after');
} else if (child.isKind('mspace')) {
const linebreak = child.attributes.get('linebreak') as string;
if (linebreak !== 'nobreak') {
marked = this.markInlineBreak(marked, forcebreak, linebreak, node, child);
}
} else if ((child.isKind('mstyle') && !child.attributes.get('style') &&
!child.attributes.getExplicit('mathbackground')) || child.isKind('semantics')) {
this.markInlineBreaks(child.childNodes[0]);
if (child.getProperty('process-breaks')) {
child.setProperty('inline-breaks', true);
child.childNodes[0].setProperty('inline-breaks', true);
node.parent.setProperty('process-breaks', 'true');
}
} else if (child.isKind('mrow') && child.attributes.get('data-semantic-added')) {
this.markInlineBreaks(child);
if (child.getProperty('process-breaks')) {
child.setProperty('inline-breaks', true);
node.parent.setProperty('process-breaks', 'true');
postbreak = (linebreak === 'newline');
} else {
postbreak = false;
if ((child.isKind('mstyle') && !child.attributes.get('style') &&
!child.attributes.getExplicit('mathbackground')) || child.isKind('semantics')) {
this.markInlineBreaks(child.childNodes[0]);
if (child.getProperty('process-breaks')) {
child.setProperty('inline-breaks', true);
child.childNodes[0].setProperty('inline-breaks', true);
node.parent.setProperty('process-breaks', 'true');
}
} else if (child.isKind('mrow') && child.attributes.get('data-semantic-added')) {
this.markInlineBreaks(child);
if (child.getProperty('process-breaks')) {
child.setProperty('inline-breaks', true);
node.parent.setProperty('process-breaks', 'true');
}
}
}
}
Expand All @@ -462,6 +471,9 @@ export abstract class CommonOutputJax<
//
child.removeProperty('forcebreak');
mo?.removeProperty('forcebreak');
if (linebreak === 'newline') {
child.setProperty('newline', true);
}
}
if (!marked) {
node.setProperty('process-breaks', true);
Expand Down

0 comments on commit 55699fb

Please sign in to comment.