diff --git a/CSharpMath.Core.Tests/Atom/LaTeXParserTest.cs b/CSharpMath.Core.Tests/Atom/LaTeXParserTest.cs index bb6a4b32..423097b3 100644 --- a/CSharpMath.Core.Tests/Atom/LaTeXParserTest.cs +++ b/CSharpMath.Core.Tests/Atom/LaTeXParserTest.cs @@ -42,6 +42,8 @@ public static Action CheckAtom [InlineData(".", new[] { typeof(Number) }, ".")] [InlineData("(", new[] { typeof(Open) }, "(")] [InlineData(")", new[] { typeof(Close) }, ")")] + [InlineData(@"\lbrack", new[] { typeof(Open) }, "[")] + [InlineData(@"\rbrack", new[] { typeof(Close) }, "]")] [InlineData(",", new[] { typeof(Punctuation) }, ",")] [InlineData("?!", new[] { typeof(Punctuation), typeof(Punctuation) }, "?!")] [InlineData("=", new[] { typeof(Relation) }, "=")] @@ -287,6 +289,7 @@ public void TestKet() { InlineData(@"\left ( 2 \right )", new[] { typeof(Inner) }, new[] { typeof(Number) }, @"(", @")", @"\left( 2\right) "), // commands InlineData(@"\left\{ 2 \right\}", new[] { typeof(Inner) }, new[] { typeof(Number) }, @"{", @"}", @"\left\{ 2\right\} "), + InlineData(@"\left\lbrack 2 \right\rbrack", new[] { typeof(Inner) }, new[] { typeof(Number) }, @"[", @"]", @"\left[ 2\right] "), // complex commands InlineData(@"\left\langle x \right\rangle", new[] { typeof(Inner) }, new[] { typeof(Variable) }, "\u2329", "\u232A", @"\left< x\right> "), // bars @@ -321,6 +324,27 @@ public void TestLeftRight( Assert.Equal(expectedLatex, LaTeXParser.MathListToLaTeX(list).ToString()); } + [Theory] + [InlineData(@"[x]", @"\lbrack x\rbrack")] + [InlineData(@"[x^2]", @"\lbrack x^2\rbrack")] + [InlineData(@"{[x]}^2", @"{\lbrack x\rbrack}^2")] + [InlineData(@"\left[x+\left[y\right]\right]", @"\left\lbrack x+\left\lbrack y\right\rbrack\right\rbrack")] + [InlineData(@"\left[x\right.", @"\left\lbrack x\right.")] + [InlineData(@"\left.x\right]", @"\left.x\right\rbrack")] + public void BracketAliasesHaveLiteralStructuralModel(string literal, string alias) { + var literalList = ParseLaTeX(literal); + var aliasList = ParseLaTeX(alias); + Assert.Equal(literalList, aliasList); + Assert.Equal(LaTeXParser.MathListToLaTeX(literalList).ToString(), + LaTeXParser.MathListToLaTeX(aliasList).ToString()); + } + + [Fact] + public void UnclosedAliasLeftReportsMissingRight() { + var (_, error) = new LaTeXParser(@"\left\lbrack x").Build(); + Assert.Contains(@"Missing \right for \left with delimiter [", error); + } + [Theory] [InlineData(@"1 \over c", @"\frac{1}{c}", true)] [InlineData(@"1 \atop c", @"{1 \atop c}", false)] @@ -1634,4 +1658,4 @@ public void TestErrorSurrogates() { } } } -} \ No newline at end of file +} diff --git a/CSharpMath/Atom/LaTeXSettings.cs b/CSharpMath/Atom/LaTeXSettings.cs index 3ef5599a..f3bc6e12 100644 --- a/CSharpMath/Atom/LaTeXSettings.cs +++ b/CSharpMath/Atom/LaTeXSettings.cs @@ -42,6 +42,8 @@ public static class LaTeXSettings { { @"\Uparrow", new Boundary("⇑") }, { @"[", new Boundary("[") }, { @"]", new Boundary("]") }, + { @"\lbrack", new Boundary("[") }, + { @"\rbrack", new Boundary("]") }, { @"\downarrow", new Boundary("↓") }, { @"\Downarrow", new Boundary("⇓") }, { @"\{", @"\lbrace", new Boundary("{") }, @@ -516,6 +518,8 @@ atom is Accent accent { @")", new Close(")") }, { @"[", new Open("[") }, { @"]", new Close("]") }, + { @"\lbrack", new Open("[") }, + { @"\rbrack", new Close("]") }, { @"\lceil", new Open("⌈") }, { @"\rceil", new Close("⌉") }, { @"\lfloor", new Open("⌊") }, @@ -1189,4 +1193,4 @@ atom is Accent accent // \varsupsetneqq -> ⫌ + U+FE00 (Variation Selector 1) Not dealing with variation selectors, thank you very much }; } -} \ No newline at end of file +}