Skip to content

Commit e873370

Browse files
committed
Ease restrictions on when infix base becomes double pipe fenced
fixes #142
1 parent 4469d38 commit e873370

5 files changed

Lines changed: 16 additions & 4 deletions

File tree

demo/test-cases.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ <h2>Super and Subscripts</h2>
283283
<test-case display="block">(X^T)_ i.,j = X_ j.,i</test-case>
284284
<test-case display="block">||bf a||^2</test-case>
285285
<test-case display="block">|bf b|_i</test-case>
286+
<test-case display="block">||a*b||^2</test-case>
286287

287288
<test-case display="block">
288289
ln x = int_1^x 1/t dt

src/compiler/parser/handlers/infix.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,16 @@ function rightAssociate(op, [left, right]) {
210210
* @returns {boolean}
211211
*/
212212
function isPipeDelimited(nodes) {
213-
if (nodes.length !== 3) {
213+
if (nodes.length < 3) {
214214
return false;
215215
}
216216

217-
const [open, , close] = nodes;
217+
const open = nodes.at(0);
218+
const close = nodes.at(-1);
218219

219220
return (
220-
open.type === "OperatorLiteral" &&
221-
close.type === "OperatorLiteral" &&
221+
open?.type === "OperatorLiteral" &&
222+
close?.type === "OperatorLiteral" &&
222223
(open.value === "|" || open.value === "∥" || open.value === "‖") &&
223224
open.value === close.value
224225
);

test/snapshots/sub-supscripts.js.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,9 @@ Generated by [AVA](https://avajs.dev).
9999
> Snapshot 1
100100
101101
'<math><msub><mrow><mo>|</mo><mi>𝐛</mi><mo>|</mo></mrow><mi>i</mi></msub></math>'
102+
103+
## Norm of the dot product square
104+
105+
> Snapshot 1
106+
107+
'<math><msup><mrow><mo>‖</mo><mi>a</mi><mo>·</mo><mi>b</mi><mo>‖</mo></mrow><mn>2</mn></msup></math>'
42 Bytes
Binary file not shown.

test/sub-supscripts.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ test("Square of a norm", (t) => {
6868
test("Index of a magnitute", (t) => {
6969
t.snapshot(render("|bf b|_i"));
7070
});
71+
72+
test("Norm of the dot product square", (t) => {
73+
t.snapshot(render("||a*b||^2"));
74+
});

0 commit comments

Comments
 (0)