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); }
internal static int GetInterElementSpaceArrayIndexForType(MathAtomType atomType) { switch (atomType) { case MathAtomType.RaiseBox: return(0); //Same as Color } return(-1); // If reach here, then WILL THROW }
public static string ToText(this MathAtomType itemType) { // Insert a space before every capital letter other than the first one. var itemString = itemType.ToString(); var chars = new StringBuilder(itemString); for (int i = itemString.Length - 1; i > 0; i--) { if (char.IsUpper(chars[i])) { chars.Insert(i, ' '); } } return(chars.ToString()); }
public static IEnumerable <(string, MathAtomType[], int, MathAtomType[], string, string, string)> RawTestDataLeftRight() { var singletonList = new MathAtomType[] { MathAtomType.Inner }; var singletonNumber = new MathAtomType[] { MathAtomType.Number }; var singletonVariable = new MathAtomType[] { MathAtomType.Variable }; yield return(@"\left( 2 \right)", singletonList, 0, singletonNumber, @"(", @")", @"\left( 2\right) "); // spacing yield return(@"\left ( 2 \right )", singletonList, 0, singletonNumber, @"(", @")", @"\left( 2\right) "); // commands yield return(@"\left\{ 2 \right\}", singletonList, 0, singletonNumber, @"{", @"}", @"\left\{ 2\right\} "); // complex commands yield return(@"\left\langle x \right\rangle", singletonList, 0, singletonVariable, "\u2329", "\u232A", @"\left< x\right> "); // bars yield return(@"\left| x \right\|", singletonList, 0, singletonVariable, @"|", "\u2016", @"\left| x\right\| "); // inner in between yield return(@"5 + \left( 2 \right) - 2", new MathAtomType[] { MathAtomType.Number, MathAtomType.BinaryOperator, MathAtomType.Inner, MathAtomType.BinaryOperator, MathAtomType.Number }, 2, singletonNumber, @"(", @")", @"5+\left( 2\right) -2"); // long inner yield return(@"\left( 2 + \frac12\right)", singletonList, 0, new MathAtomType[] { MathAtomType.Number, MathAtomType.BinaryOperator, MathAtomType.Fraction }, @"(", @")", @"\left( 2+\frac{1}{2}\right) "); // nested yield return(@"\left[ 2 + \left|\frac{-x}{2}\right| \right]", singletonList, 0, new MathAtomType[] { MathAtomType.Number, MathAtomType.BinaryOperator, MathAtomType.Inner }, @"[", @"]", @"\left[ 2+\left| \frac{-x}{2}\right| \right] "); // With scripts yield return(@"\left( 2 \right)^2", singletonList, 0, singletonNumber, @"(", @")", @"\left( 2\right) ^{2}"); // Scripts on left yield return(@"\left(^2 \right )", singletonList, 0, new MathAtomType[] { MathAtomType.Ordinary }, @"(", @")", @"\left( {}^{2}\right) "); // Dot yield return(@"\left( 2 \right.", singletonList, 0, singletonNumber, @"(", @"", @"\left( 2\right. "); }
public static MathAtom Create(MathAtomType type, string value) { switch (type) { case MathAtomType.Accent: return(new Accent(value)); case MathAtomType.Color: return(new Color()); case MathAtomType.Fraction: return(new Fraction()); case MathAtomType.Inner: return(new Inner()); case MathAtomType.LargeOperator: throw new ArgumentException( "Do not use Create(MathAtomType.LargeOperator, string)." + "Use Operator(string, bool?, bool) instead.", nameof(type)); case MathAtomType.Overline: return(new Overline()); case MathAtomType.Underline: return(new Underline()); case MathAtomType.Space: throw new ArgumentException( "Do not use Create(MathAtomType.Space, string)." + "Use Space(int, bool) instead.", nameof(type)); default: return(new MathAtom(type, value)); } }
public static MathAtom Create(MathAtomType type, char value) => Create(type, value.ToString());
internal _ExtensionAtom(MathAtomType type) : base(type, string.Empty) { }
private void CheckAtomTypeAndNucleus(IMathAtom atom, MathAtomType type, string nucleus) { Assert.Equal(type, atom.AtomType); Assert.Equal(nucleus, atom.Nucleus); }
internal static int GetInterElementSpaceArrayIndexForType <TFont, TGlyph>(Typesetter <TFont, TGlyph> t, MathAtomType atomType) where TFont : MathFont <TGlyph> { switch (atomType) { case MathAtomType.RaiseBox: return(0); //Same as Color } return(-1); // If reach here, then WILL THROW }
public Radical(MathAtomType type, string value) : this() { }