Beispiel #1
0
        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);
        }
Beispiel #2
0
 public void SetMathList(IMathList mathList)
 {
     _mathList = mathList;
     Latex     = MathListBuilder.MathListToString(mathList);
     InvalidateIntrinsicContentSize();
     SetNeedsLayout();
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        public void TestErrors(string badInput)
        {
            var builder = new MathListBuilder(badInput);
            var list    = builder.Build();

            Assert.Null(list);
            Assert.NotNull(builder.Error);
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        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);
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
        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);
        }
Beispiel #24
0
        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);
        }
Beispiel #25
0
        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");
        }
Beispiel #26
0
        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);
        }
Beispiel #27
0
        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);
        }
Beispiel #28
0
        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);
        }
Beispiel #29
0
        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);
        }
Beispiel #30
0
        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);
        }