Esempio n. 1
0
        public CommandProcessingResult ProcessCommand(CommandContext context)
        {
            var position = context.ArgumentsStartPosition;
            var source   = context.CommandSource;

            if (position == source.Length)
            {
                throw new TexParseException("illegal end!");
            }

            var cellsSource  = TexFormulaParser.ReadElement(source, ref position);
            var matrixSource = context.CommandSource.Segment(
                context.CommandNameStartPosition,
                position - context.CommandNameStartPosition);

            var cells  = ReadMatrixCells(context.Parser, context.Formula, cellsSource, context.Environment);
            var matrix = new MatrixAtom(matrixSource, cells, _cellAlignment);

            SymbolAtom GetDelimiter(string name) =>
            name == null
                    ? null
                    : TexFormulaParser.GetDelimiterSymbol(name, null) ??
            throw new TexParseException($"The delimiter {name} could not be found");

            var leftDelimiter  = GetDelimiter(_leftDelimiterSymbolName);
            var rightDelimiter = GetDelimiter(_rightDelimiterSymbolName);

            var atom = leftDelimiter == null && rightDelimiter == null
                ? (Atom)matrix
                : new FencedAtom(
                matrixSource,
                matrix,
                leftDelimiter,
                rightDelimiter);

            return(new CommandProcessingResult(atom, position));
        }
Esempio n. 2
0
 public void AddEmbraced(TexFormula formula, string leftSymbol, string rightSymbol) => Add(new FencedAtom(formula?.RootAtom, TexFormulaParser.GetDelimiterSymbol(leftSymbol),
                                                                                                          TexFormulaParser.GetDelimiterSymbol(rightSymbol)));