Atom Root(TexFormula formula, string value, ref int position)
        {
            TexFormula degreeFormula = Parse(ReadInsideBracket(value, ref position));

            return(Radical.Get(Parse(ReadGroup(value, ref position, leftGroupChar, rightGroupChar))
                               .ExtractRoot(), degreeFormula == null ? null : degreeFormula.ExtractRoot()));
        }
예제 #2
0
 public void Add(TexFormula formula)
 {
     if (formula.RootAtom is RowAtom)
     {
         Add(RowAtom.Get(formula.ExtractRoot()));
     }
     else
     {
         Add(formula.RootAtom);
     }
 }
예제 #3
0
        private Atom AttachScripts(TexFormula formula, string value, ref int position, Atom atom)
        {
            if (position == value.Length)
            {
                return(atom);
            }
            if (value[position] == superScriptChar || value[position] == subScriptChar)
            {
                if (position == value.Length - 1)
                {
                    position++;
                    return(atom);
                }
            }
            else
            {
                return(atom);
            }

            TexFormula superscriptFormula = null;
            TexFormula subscriptFormula   = null;

            //0: Undetermined; 1: Not Yet; 2: Yes, we are; 3: Yes, and make it smaller
            int markAsBig = 0;
            //0: In Beginning;1: We are in _;2: we are in ^
            int lastIsSuper = 0;

            while (position < value.Length)
            {
                var ch = value[position];
                if (ch == superScriptChar || ch == subScriptChar)
                {
                    if (++position < value.Length && (value[position] == ch))
                    {
                        markAsBig = 2;
                        if (++position < value.Length && (value[position] == ch))
                        {
                            markAsBig = 3;
                            position++;
                        }
                    }
                    bool v = ch == superScriptChar;
                    if ((v ? superscriptFormula : subscriptFormula) == null)
                    {
                        lastIsSuper = v ? 2 : 1;
                    }
                    continue;
                }
                else if (ch == rightGroupChar || (value[position - 1] != '^' && value[position - 1] != '_'))
                {
                    break;
                }
                if (lastIsSuper == 2)
                {
                    if (superscriptFormula == null)
                    {
                        superscriptFormula = ReadScript(formula, value, ref position);
                    }
                    else
                    {
                        position--;
                        superscriptFormula.RootAtom = AttachScripts(formula, value, ref position, superscriptFormula.RootAtom);
                    }
                }
                else if (lastIsSuper == 1)
                {
                    if (subscriptFormula == null)
                    {
                        subscriptFormula = ReadScript(formula, value, ref position);
                    }
                    else
                    {
                        position--;
                        subscriptFormula.RootAtom = AttachScripts(formula, value, ref position, subscriptFormula.RootAtom);
                    }
                }
                else
                {
                    break;
                }
            }
            if (superscriptFormula == null && subscriptFormula == null)
            {
                return(atom);
            }

            // Check whether to return Big Operator or Scripts.
            if (atom != null && (atom.RightType == CharType.BigOperator || markAsBig >= 2))
            {
                return(BigOperatorAtom.Get(atom, subscriptFormula == null ? null : subscriptFormula.ExtractRoot(),
                                           superscriptFormula == null ? null : superscriptFormula.ExtractRoot(), markAsBig == 3));
            }
            else
            {
                return(ScriptsAtom.Get(atom, subscriptFormula == null ? null : subscriptFormula.ExtractRoot(),
                                       superscriptFormula == null ? null : superscriptFormula.ExtractRoot()));
            }
        }