public CommandProcessingResult ProcessCommand(CommandContext context) { var source = context.CommandSource; var position = context.ArgumentsStartPosition; var topFormula = context.Parser.Parse( TexFormulaParser.ReadElement(source, ref position), context.Formula.TextStyle, context.Environment.CreateChildEnvironment()); var bottomFormula = context.Parser.Parse( TexFormulaParser.ReadElement(source, ref position), context.Formula.TextStyle, context.Environment.CreateChildEnvironment()); var start = context.CommandNameStartPosition; var atomSource = source.Segment(start, position - start); var topAtom = new List <Atom?> { topFormula.RootAtom }; var bottomAtom = new List <Atom?> { bottomFormula.RootAtom }; var atoms = new List <List <Atom?> > { topAtom, bottomAtom }; var matrixAtom = new MatrixAtom(atomSource, atoms, MatrixCellAlignment.Center); var left = new SymbolAtom(atomSource, "(", TexAtomType.Opening, true); var right = new SymbolAtom(atomSource, ")", TexAtomType.Closing, true); var fencedAtom = new FencedAtom(atomSource, matrixAtom, left, right); return(new CommandProcessingResult(fencedAtom, position)); }
public CommandProcessingResult ProcessCommand(CommandContext context) { var source = context.CommandSource; var position = context.ArgumentsStartPosition; var underlineFormula = context.Parser.Parse( TexFormulaParser.ReadElement(source, ref position), context.Formula.TextStyle, context.Environment); var start = context.CommandNameStartPosition; var atomSource = source.Segment(start, position - start); var atom = new UnderlinedAtom(atomSource, underlineFormula.RootAtom); return(new CommandProcessingResult(atom, position)); }
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)); }