Example #1
0
        public static void ParseMatrixVertical(List <Atom> el, List <List <Atom> > childs)
        {
            Last(childs).Add(ObjPool <RowAtom> .Get());
            int vPool = 0, hPool = 0;

            foreach (Atom a in el)
            {
                if (a is SymbolAtom)
                {
                    var b = ((SymbolAtom)a);
                    if (b.Name == "ampersand")
                    {
                        hPool++;
                        Last(childs).Add(RowAtom.Get());
                        vPool = 0;
                        for (int i = 0; i < childs.Count; i++)
                        {
                            if (childs[i].Count < hPool + 1)
                            {
                                childs[i].Add(RowAtom.Get());
                            }
                        }
                        b.Flush();
                    }
                    else if (b.Name == "mid")
                    {
                        vPool++;
                        if (childs.Count <= vPool)
                        {
                            childs.Add(new List <Atom>());
                            while (Last(childs).Count < hPool + 1)
                            {
                                Last(childs).Add(RowAtom.Get());
                            }
                        }
                        b.Flush();
                    }
                }
                else if (a is CharAtom)
                {
                    var b = ((CharAtom)a);
                    if (b.Character == 0x26 /*ampersand*/)
                    {
                        hPool++;
                        Last(childs).Add(RowAtom.Get());
                        vPool = 0;
                        for (int i = 0; i < childs.Count; i++)
                        {
                            if (childs[i].Count < hPool + 1)
                            {
                                childs[i].Add(RowAtom.Get());
                            }
                        }
                        b.Flush();
                    }
                    else if (b.Character == 0x7c)
                    {
                        vPool++;
                        if (childs.Count <= vPool)
                        {
                            childs.Add(new List <Atom>());
                            while (Last(childs).Count < hPool + 1)
                            {
                                Last(childs).Add(RowAtom.Get());
                            }
                        }
                        b.Flush();
                    }
                    else
                    {
                        ((RowAtom)Last(childs[vPool])).Add(a);
                    }
                }
                else
                {
                    ((RowAtom)Last(childs[vPool])).Add(a);
                }
            }
        }
Example #2
0
        private void ProcessEscapeSequence(TexFormula formula, string value, ref int position)
        {
            position++;

            var command = LookForAWord(value, ref position);

            // Check if there's no command
            if (command.Length == 0)
            {
                if (position < value.Length)
                {
                    var nextChar = value[position];
                    if (IsParserReserved(nextChar))
                    {
                        formula.Add(ConvertCharacter(value, ref position, nextChar));
                    }
                }
                return;
            }

            //Check if the command registered in Commands
            if (isCommandRegistered(command))
            {
                formula.Add(AttachScripts(formula, value, ref position,
                                          ProcessCommand(formula, value, ref position, command)));
                return;
            }

            //Check if the command registered in FontID
            var fontID = TEXPreference.main.GetFontIndexByID(command);

            if (fontID != -1)
            {
                SkipWhiteSpace(value, ref position);
                formula.Add(ParseFontStyle(value, ref position, fontID,
                                           ParseFontStyle(ReadInsideBracket(value, ref position))));
                return;
            }

            SymbolAtom symbolAtom = SymbolAtom.GetAtom(command);

            //Check if the command registered in Symbol database

            if (symbolAtom != null)
            {
                // Symbol was found.
                if (symbolAtom.RightType == CharType.Accent && formula.RootAtom != null)
                {
                    //Accent is Found
                    Atom baseAtom = formula.RootAtom;
                    if (baseAtom is RowAtom)
                    {
                        var row = (RowAtom)baseAtom;
                        baseAtom = MatrixAtom.Last(row.Elements);
                        row.Elements.RemoveAt(row.Elements.Count - 1);
                    }
                    else
                    {
                        formula.RootAtom = null;
                    }

                    formula.Add(AttachScripts(formula, value, ref position, AccentedAtom.Get(baseAtom, symbolAtom)));
                }
                else
                {
                    formula.Add(AttachScripts(formula, value, ref position, symbolAtom));
                }
                return;
            }

            //No lucks, now ...

            {
                // Command aren't defined, use it as command text style
                RowAtom row = RowAtom.Get();
                for (int i = 0; i < command.Length; i++)
                {
                    var charAtom = CharAtom.Get(command[i],
                                                TEXConfiguration.main.Typeface_Commands);
                    row.Add(charAtom);
                }
                formula.Add(AttachScripts(formula, value, ref position, row));
            }
        }