fix: bracket a fraction only where the slash would split it (#20)
This commit was merged in pull request #20.
This commit is contained in:
@@ -24,10 +24,35 @@ describe("renderLatex", () => {
|
||||
expect(renderLatex("\\int_{0}^{\\infty}")).toBe("∫₀<sup>∞</sup>");
|
||||
});
|
||||
|
||||
it("linearises a fraction and brackets only what needs it", () => {
|
||||
it("linearises a fraction and brackets only what the slash would split", () => {
|
||||
expect(renderLatex("\\frac{1}{2}")).toBe("1/2");
|
||||
expect(renderLatex("\\frac{a}{b}")).toBe("a/b");
|
||||
expect(renderLatex("\\frac{a+b}{c}")).toBe("(a+b)/c");
|
||||
expect(renderLatex("\\frac{a+b}{c}")).toBe("(a+b) / c");
|
||||
});
|
||||
|
||||
it("leaves a numerator that is one product unbracketed", () => {
|
||||
// `n(n+1)/2` is unambiguous. Asking whether the operand was a single token
|
||||
// instead produced `(n(n+1))/2`, which is a wall of parentheses.
|
||||
expect(renderLatex("\\frac{n(n+1)}{2}")).toBe("n(n+1)/2");
|
||||
expect(renderLatex("\\frac{\\sqrt{\\pi}}{2}")).toBe("√π/2");
|
||||
expect(renderLatex("E = \\frac{mc^2}{\\sqrt{1 - v^2/c^2}}")).toBe("E = mc²/√(1 − v²/c²)");
|
||||
});
|
||||
|
||||
it("brackets a denominator of more than one term, because 1/2a is read two ways", () => {
|
||||
expect(renderLatex("\\frac{1}{2a}")).toBe("1 / (2a)");
|
||||
expect(renderLatex("\\frac{\\pi}{2}")).toBe("π/2");
|
||||
});
|
||||
|
||||
it("brackets a sum so the slash cannot divide only its last term", () => {
|
||||
expect(renderLatex("\\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}")).toBe("(−b ± √(b² − 4ac)) / (2a)");
|
||||
expect(renderLatex("\\frac{\\sin x}{x}")).toBe("(sin x) / x");
|
||||
});
|
||||
|
||||
it("reads through a script rather than counting it as a split", () => {
|
||||
// The sum is above the line by construction, so it needs no brackets. A
|
||||
// script with no Unicode form is what puts a tag in the way of the scan.
|
||||
expect(renderLatex("\\frac{x^{a/b}}{y}")).toBe("x<sup>a/b</sup>/y");
|
||||
expect(renderLatex("\\frac{x^{a+b}}{y}")).toBe("xᵃ⁺ᵇ/y");
|
||||
});
|
||||
|
||||
it("renders a root, using the root sign for the degree it has", () => {
|
||||
|
||||
Reference in New Issue
Block a user