Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion CSharpMath.Core.Tests/Atom/LaTeXParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static Action<MathAtom> CheckAtom<T>
[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) }, "=")]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -1634,4 +1658,4 @@ public void TestErrorSurrogates() {
}
}
}
}
}
6 changes: 5 additions & 1 deletion CSharpMath/Atom/LaTeXSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("{") },
Expand Down Expand Up @@ -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("⌊") },
Expand Down Expand Up @@ -1189,4 +1193,4 @@ atom is Accent accent
// \varsupsetneqq -> ⫌ + U+FE00 (Variation Selector 1) Not dealing with variation selectors, thank you very much
};
}
}
}
Loading