Beispiel #1
0
        public void TestVariablesAndNumbers()
        {
            var mathList = MathLists.FromString("xy2w");

            var display = Typesetter <TFont, TGlyph> .CreateLine(mathList, _font, _context, LineStyle.Display);

            Assert.NotNull(display);
            Assert.Equal(LinePosition.Regular, display.LinePosition);
            Assert.Equal(new PointF(), display.Position);
            Assert.Equal(new Range(0, 4), display.Range);
            Assert.False(display.HasScript);
            Assert.Equal(Range.UndefinedInt, display.IndexInParent);
            Assert.Single(display.Displays);

            var sub0 = display.Displays[0];
            var line = sub0 as TextLineDisplay <TFont, TGlyph>;

            Assert.NotNull(line);
            Assert.Equal(4, line.Atoms.Length);
            Assert.Equal("xy2w", line.StringText());
            Assert.Equal(new PointF(), line.Position);
            Assert.Equal(new Range(0, 4), line.Range);
            Assert.False(line.HasScript);

            Assert.Equal(display.Ascent, line.Ascent);
            Assert.Equal(display.Descent, line.Descent);
            Assert.Equal(display.Width, line.Width);
            Assertions.ApproximatelyEqual(14, display.Ascent, 0.01);
            Assertions.ApproximatelyEqual(4, display.Descent, 0.01);
            Assertions.ApproximatelyEqual(40, display.Width, 0.01);
        }
Beispiel #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
0
        public void TestEquationWithOperatorsAndRelations()
        {
            var mathList = MathLists.FromString("2x+3=y");
            var display  = Typesetter <TFont, TGlyph> .CreateLine(mathList, _font, _context, LineStyle.Display);

            Assert.Equal(LinePosition.Regular, display.LinePosition);
            Assert.Equal(new Range(0, 6), display.Range);
            Assert.False(display.HasScript);
            Assert.Equal(Range.UndefinedInt, display.IndexInParent);
            Assert.Single(display.Displays);

            var line = display.Displays[0] as TextLineDisplay <TFont, TGlyph>;

            Assert.Equal(6, line.Atoms.Length);
            Assert.Equal("2x+3=y", line.StringText());
            Assert.Equal(new PointF(), line.Position);
            Assert.Equal(new Range(0, 6), line.Range);
            Assert.False(line.HasScript);

            Assert.Equal(display.Ascent, line.Ascent);
            Assert.Equal(display.Width, line.Width);
            Assert.Equal(display.Descent, line.Descent);

            Assertions.ApproximatelyEqual(14, display.Ascent, 0.01);
            Assertions.ApproximatelyEqual(4, display.Descent, 0.01);
            Assertions.ApproximatelyEqual(80, display.Width, 0.01);
        }
Beispiel #11
0
        public void TestSubscript()
        {
            var input     = @"-52x^{13+y}_{15-} + (-12.3 *)\frac{-12}{15.2}";
            var list      = MathLists.FromString(input);
            var finalized = new MathList(list, true);

            MathListValidator.CheckListContents(finalized);
            var reFinalized = new MathList(finalized, true);

            MathListValidator.CheckListContents(reFinalized);
        }
Beispiel #12
0
        public void SetLatex(string latex)
        {
            Latex = latex;
            (_mathList, ErrorMessage) = MathLists.BuildResultFromString(latex);
            if (_mathList != null)
            {
                _CreateDisplayList();
            }
            InvalidateIntrinsicContentSize();

            SetNeedsLayout();
        }
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 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 #16
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 #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 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 #20
0
        public void TestCopyUnderline()
        {
            var atom1 = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Times;
            var atom3 = MathAtoms.Divide;

            var list = MathLists.WithAtoms(atom1, atom2, atom3);

            var under = new Underline();

            Assert.Equal(MathAtomType.Underline, under.AtomType);
            under.InnerList = list;

            var copy = new Underline(under, false);

            CheckClone(copy, under);
            CheckClone(copy.InnerList, under.InnerList);
        }
Beispiel #21
0
        public void TestCopyAccent()
        {
            var atom1 = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Times;
            var atom3 = MathAtoms.Divide;

            var list = MathLists.WithAtoms(atom1, atom2, atom3);

            var accent = new Accent("^");

            Assert.Equal(MathAtomType.Accent, accent.AtomType);
            accent.InnerList = list;

            var copy = new Accent(accent, false);

            CheckClone(copy, accent);
            CheckClone(copy.InnerList, accent.InnerList);
        }
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 TestCopyRadical()
        {
            var atom  = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Times;
            var atom3 = MathAtoms.Divide;

            var list  = MathLists.WithAtoms(atom, atom2, atom3);
            var list2 = MathLists.WithAtoms(atom3, atom2);

            var radical = new Radical {
                Radicand = list,
                Degree   = list2
            };

            var copy = new Radical(radical, false);

            CheckClone(copy, radical);
            CheckClone(copy.Radicand, radical.Radicand);
            CheckClone(copy.Degree, radical.Degree);
        }
Beispiel #25
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 #26
0
        public void TestCreateMathTable()
        {
            var table = new Table();

            Assert.Equal(MathAtomType.Table, table.AtomType);

            var atom1 = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Times;
            var atom3 = MathAtoms.Divide;

            var list  = MathLists.WithAtoms(atom1, atom2, atom3);
            var list2 = MathLists.WithAtoms(atom3, atom2);

            table.SetCell(list, 3, 2);
            table.SetCell(list2, 1, 0);

            table.SetAlignment(ColumnAlignment.Left, 2);
            table.SetAlignment(ColumnAlignment.Right, 1);

            Assert.Equal(4, table.Cells.Count);
            Assert.Empty(table.Cells[0]);
            Assert.Single(table.Cells[1]);
            Assert.Empty(table.Cells[2]);
            Assert.Equal(3, table.Cells[3].Count);

            Assert.Equal(2, table.Cells[1][0].Atoms.Count);
            Assert.Equal(list2, table.Cells[1][0]);
            Assert.Empty(table.Cells[3][0].Atoms);
            Assert.Empty(table.Cells[3][1].Atoms);

            Assert.Equal(list, table.Cells[3][2]);

            Assert.Equal(4, table.NRows);
            Assert.Equal(3, table.NColumns);

            Assert.Equal(3, table.Alignments.Count);
            Assert.Equal(ColumnAlignment.Center, table.Alignments[0]);
            Assert.Equal(ColumnAlignment.Right, table.Alignments[1]);
            Assert.Equal(ColumnAlignment.Left, table.Alignments[2]);
        }
Beispiel #27
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 #28
0
        public void TestCopyInner()
        {
            var atom1 = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Times;
            var atom3 = MathAtoms.Divide;

            var list = MathLists.WithAtoms(atom1, atom2, atom3);

            var inner = new Inner {
                InnerList     = list,
                LeftBoundary  = MathAtoms.Create(MathAtomType.Boundary, "("),
                RightBoundary = MathAtoms.Create(MathAtomType.Boundary, ")")
            };

            Assert.Equal(MathAtomType.Inner, inner.AtomType);

            var copy = new Inner(inner, false);

            CheckClone(inner, copy);
            CheckClone(inner.InnerList, copy.InnerList);
            CheckClone(inner.LeftBoundary, copy.LeftBoundary);
            CheckClone(inner.RightBoundary, copy.RightBoundary);
        }
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 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);
        }