Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #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);
        }
Exemple #9
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);
        }
Exemple #10
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);
        }
Exemple #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);
        }
Exemple #12
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);
        }
Exemple #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);
        }
Exemple #14
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);
        }
Exemple #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);
        }
Exemple #16
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);
        }
Exemple #17
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);
        }
Exemple #18
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);
        }
Exemple #19
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);
        }
Exemple #20
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);
        }
Exemple #21
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);
        }
Exemple #22
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);
        }
Exemple #23
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);
        }
Exemple #24
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);
        }
Exemple #25
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);
        }
Exemple #26
0
        public void TestFontOneCharacterInside()
        {
            var input = @"\sqrt \mathrm x y";
            var list  = MathLists.FromString(input);

            Assert.Equal(2, list.Count);

            var radical = list[0] as IRadical;

            CheckAtomTypeAndNucleus(radical, MathAtomType.Radical, "");

            var sublist = radical.Radicand;
            var atom    = sublist[0];

            CheckAtomTypeAndNucleus(atom, MathAtomType.Variable, "x");
            Assert.Equal(FontStyle.Roman, atom.FontStyle);

            CheckAtomTypeAndNucleus(list[1], MathAtomType.Variable, "y");
            Assert.Equal(FontStyle.Default, list[1].FontStyle);

            var latex = MathListBuilder.MathListToString(list);

            Assert.Equal(@"\sqrt{\mathrm{x}}y", latex);
        }
Exemple #27
0
 void TestOuter(string latex, int rangeMax, double ascent, double descent, double width,
                params System.Action <IDisplay <TFont, TGlyph> >[] inspectors) =>
 TestList(rangeMax, ascent, descent, width, 0, 0, LinePosition.Regular, Range.UndefinedInt, inspectors)
     (_context.CreateLine(MathLists.FromString(latex), _font, LineStyle.Display));