예제 #1
0
        public void PutDelimiterUnder(TexDelimeter delimiter, TexFormula subscriptName, TexUnit kernUnit, double kern)
        {
            var name = TexFormulaParser.DelimiterNames[(int)delimiter][(int)TexDelimeterType.Under];

            Formula.RootAtom = new OverUnderDelimiter(Formula.RootAtom,
                                                      subscriptName?.RootAtom, SymbolAtom.GetAtom(name), kernUnit, kern, false);
        }
예제 #2
0
        public void PutDelimiterUnder(TexDelimeter delimiter)
        {
            var name = TexFormulaParser.DelimiterNames[(int)delimiter][(int)TexDelimeterType.Under];

            Formula.RootAtom = new OverUnderDelimiter(Formula.RootAtom, null, SymbolAtom.GetAtom(name),
                                                      TexUnit.Ex, 0, false);
        }
예제 #3
0
        public void PutDelimiterOver(TexDelimiter delimiter)
        {
            var name = TexFormulaParser.DelimiterNames[(int)delimiter][(int)TexDelimeterType.Over];

            this.Formula.RootAtom = new OverUnderDelimiter(
                this.source,
                this.Formula.RootAtom,
                null,
                SymbolAtom.GetAtom(name, null),
                TexUnit.Ex,
                0.0,
                true);
        }
예제 #4
0
        internal static SymbolAtom GetDelimiterSymbol(string name, SourceSpan source)
        {
            if (name == null)
            {
                return(null);
            }

            var result = SymbolAtom.GetAtom(name, source);

            if (!result.IsDelimeter)
            {
                return(null);
            }
            return(result);
        }
예제 #5
0
        public void PutDelimiterOver(
            TexDelimiter delimiter,
            TexFormula superscriptFormula,
            TexUnit kernUnit,
            double kern)
        {
            var name = TexFormulaParser.DelimiterNames[(int)delimiter][(int)TexDelimeterType.Over];

            this.Formula.RootAtom = new OverUnderDelimiter(
                this.source,
                this.Formula.RootAtom,
                superscriptFormula?.RootAtom,
                SymbolAtom.GetAtom(name, null),
                kernUnit,
                kern,
                true);
        }
예제 #6
0
        /// <remarks>May return <c>null</c>.</remarks>
        private Atom ConvertCharacter(
            TexFormula formula,
            ref int position,
            SourceSpan source,
            ICommandEnvironment environment)
        {
            var character = source[0];

            position++;
            if (IsSymbol(character) && formula.TextStyle != TexUtilities.TextStyleName)
            {
                // Character is symbol.
                var symbolName = symbols.ElementAtOrDefault(character);
                if (string.IsNullOrEmpty(symbolName))
                {
                    if (environment.ProcessUnknownCharacter(formula, character))
                    {
                        return(null);
                    }

                    throw new TexParseException($"Unknown character : '{character}'");
                }

                try
                {
                    return(SymbolAtom.GetAtom(symbolName, source));
                }
                catch (SymbolNotFoundException e)
                {
                    throw new TexParseException("The character '"
                                                + character.ToString()
                                                + "' was mapped to an unknown symbol with the name '"
                                                + (string)symbolName + "'!", e);
                }
            }
            else // Character is alpha-numeric or should be rendered as text.
            {
                return(new CharAtom(source, character, formula.TextStyle));
            }
        }
예제 #7
0
        private Atom AttachScripts(
            TexFormula formula,
            SourceSpan value,
            ref int position,
            Atom atom,
            bool skipWhiteSpace,
            ICommandEnvironment environment)
        {
            if (skipWhiteSpace)
            {
                SkipWhiteSpace(value, ref position);
            }

            var initialPosition = position;

            if (position == value.Length)
            {
                return(atom);
            }

            // Check for prime marks.
            var primesRowAtom = new RowAtom(new SourceSpan(value.Source, position, 0));
            int i             = position;

            while (i < value.Length)
            {
                if (value[i] == primeChar)
                {
                    primesRowAtom = primesRowAtom.Add(SymbolAtom.GetAtom("prime", value.Segment(i, 1)));
                    position++;
                }
                else if (!IsWhiteSpace(value[i]))
                {
                    break;
                }
                i++;
            }

            var primesRowSource = new SourceSpan(
                value.Source,
                primesRowAtom.Source.Start,
                position - primesRowAtom.Source.Start);

            primesRowAtom = primesRowAtom.WithSource(primesRowSource);

            if (primesRowAtom.Elements.Count > 0)
            {
                atom = new ScriptsAtom(primesRowAtom.Source, atom, null, primesRowAtom);
            }

            if (position == value.Length)
            {
                return(atom);
            }

            TexFormula superscriptFormula = null;
            TexFormula subscriptFormula   = null;

            var ch = value[position];

            if (ch == superScriptChar)
            {
                // Attach superscript.
                position++;
                superscriptFormula = ReadScript(formula, value, ref position, environment);

                SkipWhiteSpace(value, ref position);
                if (position < value.Length && value[position] == subScriptChar)
                {
                    // Attach subscript also.
                    position++;
                    subscriptFormula = ReadScript(formula, value, ref position, environment);
                }
            }
            else if (ch == subScriptChar)
            {
                // Add subscript.
                position++;
                subscriptFormula = ReadScript(formula, value, ref position, environment);

                SkipWhiteSpace(value, ref position);
                if (position < value.Length && value[position] == superScriptChar)
                {
                    // Attach superscript also.
                    position++;
                    superscriptFormula = ReadScript(formula, value, ref position, environment);
                }
            }

            if (superscriptFormula == null && subscriptFormula == null)
            {
                return(atom);
            }

            // Check whether to return Big Operator or Scripts.
            var subscriptAtom   = subscriptFormula?.RootAtom;
            var superscriptAtom = superscriptFormula?.RootAtom;

            if (atom.GetRightType() == TexAtomType.BigOperator)
            {
                var source = value.Segment(atom.Source.Start, position - atom.Source.Start);
                if (atom is BigOperatorAtom typedAtom)
                {
                    return(new BigOperatorAtom(
                               source,
                               typedAtom.BaseAtom,
                               subscriptAtom,
                               superscriptAtom,
                               typedAtom.UseVerticalLimits));
                }

                return(new BigOperatorAtom(source, atom, subscriptAtom, superscriptAtom));
            }
            else
            {
                var source = new SourceSpan(value.Source, initialPosition, position - initialPosition);
                return(new ScriptsAtom(source, atom, subscriptAtom, superscriptAtom));
            }
        }
예제 #8
0
 public void AddSymbol(string name, TexAtomType type)
 {
     this.Add(new SymbolAtom(null, SymbolAtom.GetAtom(name, null), type));
 }
예제 #9
0
 public void AddSymbol(string name)
 {
     Add(SymbolAtom.GetAtom(name, null));
 }
예제 #10
0
 public void AddSymbol(string name, TexAtomType type) => Add(new SymbolAtom(SymbolAtom.GetAtom(name), type));
예제 #11
0
 public void AddSymbol(string name) => Add(SymbolAtom.GetAtom(name));