Skip to content

Commit

Permalink
convert unicode prime to apostrophe in latex (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp authored Oct 29, 2023
1 parent 20e2ca7 commit bf37648
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/doenetml-worker/src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ export function normalizeLatexString(
["\u2229", " \\cap "], // ∩
["\u221E", " \\infty "], // ∞
["\u2205", " \\emptyset "], // ∅
["\u2032", "'"], // ′
];

for (let sub of substitutions) {
Expand Down
52 changes: 50 additions & 2 deletions packages/test-cypress/cypress/e2e/tagSpecific/mathinput.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10702,7 +10702,7 @@ describe("MathInput Tag Tests", function () {
expect(stateVariables["/a3"].stateValues.value).eq(Infinity);
});

cy.log(`unicode µ U+u00B5 becomes mu`);
cy.log(`unicode µ U+00B5 becomes mu`);

cy.get(cesc("#\\/a") + " textarea").type(
"{ctrl+home}{shift+end}{backspace}\u00B5{enter}",
Expand Down Expand Up @@ -10744,7 +10744,7 @@ describe("MathInput Tag Tests", function () {
expect(stateVariables["/a3"].stateValues.value).eq("mu");
});

cy.log(`unicode μ U+u03BC becomes mu`);
cy.log(`unicode μ U+03BC becomes mu`);

cy.get(cesc("#\\/a") + " textarea").type(
"{ctrl+home}{shift+end}{backspace}\u03BC{enter}",
Expand Down Expand Up @@ -10785,6 +10785,54 @@ describe("MathInput Tag Tests", function () {
expect(stateVariables["/a2"].stateValues.value).eq("mu");
expect(stateVariables["/a3"].stateValues.value).eq("mu");
});

cy.log(`unicode ′ U+2032 becomes apostrophe`);

cy.get(cesc("#\\/a") + " textarea").type(
"{ctrl+home}{shift+end}{backspace}f\u2032{enter}",
{ force: true },
);

cy.get(cesc("#\\/a") + " .mq-editable-field").should(
"contain.text",
"f\u2032",
);
cy.get(cesc("#\\/a2") + " .mjx-mrow").should("contain.text", "f\u2032");
cy.get(cesc("#\\/a3") + " .mjx-mrow").should("contain.text", "f\u2032");

cy.get(cesc("#\\/a") + " .mq-editable-field")
.invoke("text")
.then((text) => {
expect(text.replace(/[\s\u200B-\u200D\uFEFF]/g, "")).equal(
"f\u2032",
);
});
cy.get(cesc("#\\/a2"))
.find(".mjx-mrow")
.eq(0)
.invoke("text")
.then((text) => {
expect(text.trim()).equal("f\u2032");
});
cy.get(cesc("#\\/a3"))
.find(".mjx-mrow")
.eq(0)
.invoke("text")
.then((text) => {
expect(text.trim()).equal("f\u2032");
});
cy.window().then(async (win) => {
let stateVariables = await win.returnAllStateVariables1();
expect(stateVariables["/a"].stateValues.value).eqls(["prime", "f"]);
expect(stateVariables["/a2"].stateValues.value).eqls([
"prime",
"f",
]);
expect(stateVariables["/a3"].stateValues.value).eqls([
"prime",
"f",
]);
});
});

it("exponent with numbers", () => {
Expand Down

0 comments on commit bf37648

Please sign in to comment.