public void TestFractionInFraction() { var input = @"\frac1\frac23"; var list = MathLists.FromString(input); Assert.Single(list); CheckAtomTypeAndNucleus(list[0], MathAtomType.Fraction, ""); var fraction = list[0] as Fraction; var numerator = fraction.Numerator; Assert.Single(numerator); CheckAtomTypeAndNucleus(numerator[0], MathAtomType.Number, "1"); var denominator = fraction.Denominator; Assert.Single(denominator); CheckAtomTypeAndNucleus(denominator[0], MathAtomType.Fraction, ""); var subFraction = denominator[0] as Fraction; var subNumerator = subFraction.Numerator; Assert.Single(subNumerator); CheckAtomTypeAndNucleus(subNumerator[0], MathAtomType.Number, "2"); var subDenominator = subFraction.Denominator; Assert.Single(subDenominator); CheckAtomTypeAndNucleus(subDenominator[0], MathAtomType.Number, "3"); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\frac{1}{\frac{2}{3}}", latex); }
public void SetMathList(IMathList mathList) { _mathList = mathList; Latex = MathListBuilder.MathListToString(mathList); InvalidateIntrinsicContentSize(); SetNeedsLayout(); }
public void TestRadical() { string input = @"\sqrt[3]2"; var list = MathLists.FromString(input); Assert.Single(list); var radical = list[0] as Radical; CheckAtomTypeAndNucleus(radical, MathAtomType.Radical, ""); IMathList subList = radical.Radicand; Assert.Single(subList); var atom = subList[0]; CheckAtomTypeAndNucleus(atom, MathAtomType.Number, "2"); var degree = radical.Degree; Assert.Single(degree); CheckAtomTypeAndNucleus(degree[0], MathAtomType.Number, "3"); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\sqrt[3]{2}", latex); }
void TestFraction() { var input = @"\frac1c"; var list = MathLists.FromString(input); Assert.NotNull(list); Assert.Single(list); var fraction = list[0] as Fraction; Assert.NotNull(fraction); CheckAtomTypeAndNucleus(fraction, MathAtomType.Fraction, ""); Assert.True(fraction.HasRule); Assert.Null(fraction.LeftDelimiter); Assert.Null(fraction.RightDelimiter); var sublist = fraction.Numerator; Assert.Single(sublist); CheckAtomTypeAndNucleus(sublist[0], MathAtomType.Number, "1"); var denominator = fraction.Denominator; Assert.Single(denominator); CheckAtomTypeAndNucleus(denominator[0], MathAtomType.Variable, "c"); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\frac{1}{c}", latex); }
public void TestLimits() { var input = @"\int"; var list = MathLists.FromString(input); Assert.Single(list); var op = list[0] as LargeOperator; Assert.Equal(MathAtomType.LargeOperator, op.AtomType); Assert.False(op.Limits); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\int ", latex); var input2 = @"\int\limits"; var list2 = MathLists.FromString(input2); Assert.Single(list2); var op2 = list2[0] as LargeOperator; Assert.Equal(MathAtomType.LargeOperator, op2.AtomType); Assert.True(op2.Limits); var latex2 = MathListBuilder.MathListToString(list2); Assert.Equal(@"\int \limits ", latex2); }
public void TestLeftRight( string input, MathAtomType[] expectedOutputTypes, int innerIndex, MathAtomType[] expectedInnerTypes, string leftBoundary, string rightBoundary, string expectedLatex) { var builder = new MathListBuilder(input); var list = builder.Build(); Assert.NotNull(list); Assert.Null(builder.Error); ExpandGroups(list); CheckAtomTypes(list, expectedOutputTypes); var inner = list[innerIndex] as Inner; Assert.NotNull(inner); CheckAtomTypeAndNucleus(inner, MathAtomType.Inner, ""); CheckAtomTypes(inner.InnerList, expectedInnerTypes); CheckAtomTypeAndNucleus(inner.LeftBoundary, MathAtomType.Boundary, leftBoundary); CheckAtomTypeAndNucleus(inner.RightBoundary, MathAtomType.Boundary, rightBoundary); var latex = MathListBuilder.MathListToString(list); Assert.Equal(expectedLatex, latex); }
public void TestAtopInParens() { var input = @"5 + {1 \atop c} + 8"; var list = MathLists.FromString(input); Assert.Equal(5, list.Count); var types = new MathAtomType[] { MathAtomType.Number, MathAtomType.BinaryOperator, MathAtomType.Fraction, MathAtomType.BinaryOperator, MathAtomType.Number }; ExpandGroups(list); CheckAtomTypes(list, types); var fraction = list[2] as IFraction; CheckAtomTypeAndNucleus(fraction, MathAtomType.Fraction, ""); Assert.False(fraction.HasRule); Assert.Null(fraction.LeftDelimiter); Assert.Null(fraction.RightDelimiter); Assert.Single(fraction.Numerator); CheckAtomTypeAndNucleus(fraction.Numerator[0], MathAtomType.Number, "1"); Assert.Single(fraction.Denominator); CheckAtomTypeAndNucleus(fraction.Denominator[0], MathAtomType.Variable, "c"); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"5+{1 \atop c}+8", latex); }
public void TestMatrix() { var input = @"\begin{matrix} x & y \\ z & w \end{matrix}"; var list = MathLists.FromString(input); Assert.Single(list); var table = list[0] as IMathTable; CheckAtomTypeAndNucleus(table, MathAtomType.Table, ""); Assert.Equal("matrix", table.Environment); Assert.Equal(0, table.InterRowAdditionalSpacing); Assert.Equal(18, table.InterColumnSpacing); Assert.Equal(2, table.NRows); Assert.Equal(2, table.NColumns); for (int i = 0; i < 2; i++) { var alignment = table.GetAlignment(i); Assert.Equal(ColumnAlignment.Center, alignment); for (int j = 0; j < 2; j++) { var cell = table.Cells[j][i]; Assert.Equal(2, cell.Count); var style = cell[0] as IStyle; Assert.Equal(MathAtomType.Style, style.AtomType); Assert.Equal(LineStyle.Text, style.LineStyle); var atom = cell[1]; Assert.Equal(MathAtomType.Variable, atom.AtomType); } } var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\begin{matrix}x&y\\ z&w\end{matrix}", latex); }
public void TestTableWithColumns() { var input = @"x & y \\ z & w"; var list = MathLists.FromString(input); Assert.Single(list); var table = list[0] as IMathTable; CheckAtomTypeAndNucleus(table, MathAtomType.Table, ""); Assert.Null(table.Environment); Assert.Equal(1, table.InterRowAdditionalSpacing); Assert.Equal(0, table.InterColumnSpacing); Assert.Equal(2, table.NRows); Assert.Equal(2, table.NColumns); for (int i = 0; i < 2; i++) { Assert.Equal(ColumnAlignment.Left, table.GetAlignment(i)); for (int j = 0; j < 2; j++) { var cell = table.Cells[j][i]; Assert.Single(cell); Assert.Equal(MathAtomType.Variable, cell[0].AtomType); } } var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"x&y\\ z&w", latex); }
private void RunScriptTest(string input, Func <IMathAtom, IMathList> scriptGetter, MathAtomType[][] atomTypes, string output) { var builder = new MathListBuilder(input); var list = builder.Build(); Assert.Null(builder.Error); ExpandGroups(list); CheckAtomTypes(list, atomTypes[0]); IMathAtom firstAtom = list[0]; var types = atomTypes[1]; if (types.Count() > 0) { Assert.NotNull(scriptGetter(firstAtom)); } var scriptList = scriptGetter(firstAtom); CheckAtomTypes(scriptList, atomTypes[1]); if (atomTypes.Count() == 3) { // one more level var firstScript = scriptList[0]; var scriptScriptList = scriptGetter(firstScript); CheckAtomTypes(scriptScriptList, atomTypes[2]); } string latex = MathListBuilder.MathListToString(list); Assert.Equal(output, latex); }
public void TestSqrtInSqrt() { var input = @"\sqrt\sqrt2"; var list = MathLists.FromString(input); Assert.Single(list); var radical = list[0] as Radical; CheckAtomTypeAndNucleus(radical, MathAtomType.Radical, ""); var sublist = radical.Radicand; Assert.Single(sublist); CheckAtomTypeAndNucleus(sublist[0], MathAtomType.Radical, ""); var subSubList = (sublist[0] as Radical).Radicand; Assert.Single(subSubList); CheckAtomTypeAndNucleus(subSubList[0], MathAtomType.Number, "2"); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\sqrt{\sqrt{2}}", latex); }
public void TestErrors(string badInput) { var builder = new MathListBuilder(badInput); var list = builder.Build(); Assert.Null(list); Assert.NotNull(builder.Error); }
public void TestFontSingle() { var input = @"\mathbf x"; var list = MathLists.FromString(input); Assert.Single(list); CheckAtomTypeAndNucleus(list[0], MathAtomType.Variable, "x"); Assert.Equal(FontStyle.Bold, list[0].FontStyle); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\mathbf{x}", latex); }
public void TestMathSpace() { var input = @"\!"; var list = MathLists.FromString(input); Assert.Single(list); CheckAtomTypeAndNucleus(list[0], MathAtomType.Space, ""); Assert.Equal(-3, (list[0] as ISpace).Length); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\! ", latex); }
public void TestUnspecifiedLimits() { var input = @"\sum"; var list = MathLists.FromString(input); Assert.Single(list); var op = list[0] as LargeOperator; Assert.Equal(MathAtomType.LargeOperator, op.AtomType); Assert.Null(op.Limits); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\sum ", latex); }
public void TestNoLimits() { var input = @"\sum\nolimits"; var list = MathLists.FromString(input); Assert.Single(list); var op = list[0] as LargeOperator; Assert.Equal(MathAtomType.LargeOperator, op.AtomType); Assert.False(op.Limits); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\sum \nolimits ", latex); }
public void TestColor() { var input = @"\color{#F00}a"; var list = MathLists.FromString(input); Assert.Single(list); var op = list[0] as Color; Assert.Equal(MathAtomType.Color, op.AtomType); Assert.False(op.ScriptsAllowed); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\color{#F00}{a}", latex); }
public void TestFontMultipleCharacters() { var input = @"\frak{xy}"; var list = MathLists.FromString(input); Assert.Equal(2, list.Count); CheckAtomTypeAndNucleus(list[0], MathAtomType.Variable, "x"); Assert.Equal(FontStyle.Fraktur, list[0].FontStyle); CheckAtomTypeAndNucleus(list[1], MathAtomType.Variable, "y"); Assert.Equal(FontStyle.Fraktur, list[1].FontStyle); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\mathfrak{xy}", latex); }
public void TestBuilder(string input, MathAtomType[] atomTypes, string output) { var builder = new MathListBuilder(input); var list = builder.Build(); Assert.Null(builder.Error); ExpandGroups(list); CheckAtomTypes(list, atomTypes); var latex = MathListBuilder.MathListToString(list); Assert.Equal(output, latex); }
public void TestListCopyWithFusedItems() { var builder = new MathListBuilder("12+x"); var list = builder.Build(); var finalized = list.FinalizedList(); var fusedCount = finalized.Sum(atom => atom.FusedAtoms?.Count ?? 0); Assert.Equal(2, fusedCount); var copy = AtomCloner.Clone(finalized, true); var fusedCopyCount = copy.Sum(atom => atom.FusedAtoms?.Count ?? 0); Assert.Equal(2, fusedCopyCount); }
public void TestText() { var input = @"\text{x y}"; var list = MathLists.FromString(input); Assert.Equal(3, list.Count); CheckAtomTypeAndNucleus(list[0], MathAtomType.Variable, @"x"); Assert.Equal(FontStyle.Roman, list[0].FontStyle); CheckAtomTypeAndNucleus(list[1], MathAtomType.Ordinary, " "); CheckAtomTypeAndNucleus(list[2], MathAtomType.Variable, @"y"); Assert.Equal(FontStyle.Roman, list[2].FontStyle); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\mathrm{x\ y}", latex); }
public void TestAccent() { var input = @"\bar x"; var list = MathLists.FromString(input); Assert.Single(list); var accent = list[0] as IAccent; CheckAtomTypeAndNucleus(accent, MathAtomType.Accent, "\u0304"); var inner = accent.InnerList; Assert.Single(inner); CheckAtomTypeAndNucleus(inner[0], MathAtomType.Variable, "x"); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\bar{x}", latex); }
public void TestUnderline() { var input = @"\underline 2"; var list = MathLists.FromString(input); Assert.Single(list); var underline = list[0] as IUnderline; CheckAtomTypeAndNucleus(underline, MathAtomType.Underline, ""); var inner = underline.InnerList; Assert.Single(inner); CheckAtomTypeAndNucleus(inner[0], MathAtomType.Number, "2"); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\underline{2}", latex); }
public void TestMathStyle() { var input = @"\textstyle y \scriptstyle x"; var list = MathLists.FromString(input); Assert.Equal(4, list.Count); var style = list[0] as IStyle; CheckAtomTypeAndNucleus(style, MathAtomType.Style, ""); Assert.Equal(LineStyle.Text, style.LineStyle); var style2 = list[2] as IStyle; CheckAtomTypeAndNucleus(style2, MathAtomType.Style, ""); Assert.Equal(LineStyle.Script, style2.LineStyle); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"\textstyle y\scriptstyle x", latex); }
public void TestSymbols() { string str = @"5\times3^{2\div2}"; var builder = new MathListBuilder(str); var list = builder.Build(); Assert.NotNull(list); Assert.Equal(3, list.Atoms.Count()); CheckAtomTypeAndNucleus(list[0], MathAtomType.Number, "5"); CheckAtomTypeAndNucleus(list[1], MathAtomType.BinaryOperator, "\u00D7"); CheckAtomTypeAndNucleus(list[2], MathAtomType.Number, "3"); var superList = list[2].Superscript; Assert.NotNull(superList); Assert.Equal(3, superList.Atoms.Count()); CheckAtomTypeAndNucleus(superList[0], MathAtomType.Number, "2"); CheckAtomTypeAndNucleus(superList[1], MathAtomType.BinaryOperator, "\u00F7"); CheckAtomTypeAndNucleus(superList[2], MathAtomType.Number, "2"); }
public void TestCustom() { var input = @"\lcm(a,b)"; var builder = new MathListBuilder(input); var list = builder.Build(); Assert.Null(list); Assert.NotNull(builder.Error); MathAtoms.AddLatexSymbol("lcm", MathAtoms.Operator("lcm", false)); var builder2 = new MathListBuilder(input); var list2 = builder2.Build(); ExpandGroups(list2); CheckAtomTypes(list2, MathAtomType.LargeOperator, MathAtomType.Open, MathAtomType.Variable, MathAtomType.Punctuation, MathAtomType.Variable, MathAtomType.Close); var latex = MathListBuilder.MathListToString(list2); Assert.Equal(@"\lcm (a,b)", latex); }
public void TestAtop() { var input = @"1 \atop c"; var list = MathLists.FromString(input); Assert.Single(list); var fraction = list[0] as Fraction; CheckAtomTypeAndNucleus(fraction, MathAtomType.Fraction, ""); Assert.False(fraction.HasRule); Assert.Null(fraction.LeftDelimiter); Assert.Null(fraction.RightDelimiter); Assert.Single(fraction.Numerator); CheckAtomTypeAndNucleus(fraction.Numerator[0], MathAtomType.Number, "1"); Assert.Single(fraction.Denominator); CheckAtomTypeAndNucleus(fraction.Denominator[0], MathAtomType.Variable, "c"); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"{1 \atop c}", latex); }
public void TestDisplayLines(string input) { var list = MathLists.FromString(input); Assert.Single(list); var table = list[0] as IMathTable; CheckAtomTypeAndNucleus(table, MathAtomType.Table, ""); Assert.Equal(1, table.InterRowAdditionalSpacing); Assert.Equal(0, table.InterColumnSpacing); Assert.Equal(2, table.NRows); Assert.Equal(1, table.NColumns); Assert.Equal(ColumnAlignment.Center, table.GetAlignment(0)); for (int j = 0; j < 2; j++) { var cell = table.Cells[j][0]; Assert.Single(cell); Assert.Equal(MathAtomType.Variable, cell[0].AtomType); } var latex = MathListBuilder.MathListToString(list); Assert.Equal(input, latex); }
public void TestBinomial() { var input = @"\binom{n}{k}"; var list = MathLists.FromString(input); Assert.Single(list); var fraction = list[0] as IFraction; CheckAtomTypeAndNucleus(fraction, MathAtomType.Fraction, ""); Assert.False(fraction.HasRule); Assert.Equal("(", fraction.LeftDelimiter); Assert.Equal(")", fraction.RightDelimiter); Assert.Single(fraction.Numerator); CheckAtomTypeAndNucleus(fraction.Numerator[0], MathAtomType.Variable, "n"); Assert.Single(fraction.Denominator); CheckAtomTypeAndNucleus(fraction.Denominator[0], MathAtomType.Variable, "k"); var latex = MathListBuilder.MathListToString(list); Assert.Equal(@"{n \choose k}", latex); }
public void TestEqAlign(string input) { var list = MathLists.FromString(input); Assert.Single(list); var table = list[0] as IMathTable; CheckAtomTypeAndNucleus(table, MathAtomType.Table, ""); Assert.Equal(1, table.InterRowAdditionalSpacing); Assert.Equal(0, table.InterColumnSpacing); Assert.Equal(2, table.NRows); Assert.Equal(2, table.NColumns); for (int i = 0; i < 2; i++) { var alignment = table.GetAlignment(i); Assert.Equal(i == 0 ? ColumnAlignment.Right : ColumnAlignment.Left, alignment); for (int j = 0; j < 2; j++) { var cell = table.Cells[j][i]; if (i == 0) { Assert.Single(cell); Assert.Equal(MathAtomType.Variable, cell[0].AtomType); } else { Assert.Equal(2, cell.Count); Assert.Equal(MathAtomType.Ordinary, cell[0].AtomType); Assert.Equal(MathAtomType.Variable, cell[1].AtomType); } } } var latex = MathListBuilder.MathListToString(list); Assert.Equal(input, latex); }