# module MathML::LaTeX::BuiltinGroups

### Public Class Methods

new() click to toggle source
Calls superclass method

    # File lib/math_ml/latex.rb, line 830
    def initialize
            add_group("begin", "end")
            add_group("left", "right", :left_etc)
            add_group("bigg", "bigg", :left_etc)
            @environments = Hash.new

            super
    end

### Public Instance Methods

add_environment(*a) click to toggle source

    # File lib/math_ml/latex.rb, line 839
    def add_environment(*a)
            @environments = Hash.new unless @environments
            if a.size==1 && Hash===a[0]
                    @environments.merge!(hash)
            else
                    a.each{|i| @environments[i] = false}
            end
    end

grp_begin() click to toggle source

    # File lib/math_ml/latex.rb, line 848
    def grp_begin
            matched = @scanner.matched
            begin_pos = @scanner.pos-matched.size
            en = @scanner.scan_block ? @scanner[1] : @scanner.scan_any
            raise ParseError.new('Environment name not exist.') unless en

            macro = @macro.environments(en)
            if macro
                    begin
                            flg = @expanded_environment.include?(en)
                            @expanded_environment.push(en)
                            raise CircularReferenceEnvironment if flg

                            pos = @scanner.pos
                            option = (macro.option && @scanner.scan_option) ? @scanner[1] : nil
                            params = Array.new
                            (1..macro.num).each do
                                    params << (@scanner.scan_block ? @scanner[1] : @scanner.scan_any)
                                    raise ParseError.new("Need more parameter.") unless params.last
                            end
                            body = ""
                            grpnest = 0
                            until @scanner.peek_command=="end" && grpnest==0
                                    if @scanner.eos?
                                            @scanner.pos = pos
                                            raise ParseError.new('Matching \end not exist.')
                                    end
                                    com = @scanner.peek_command
                                    grpnest += 1 if @group_begins.has_key?(com)
                                    grpnest -=1 if @group_ends.has_key?(com) && @group_begins[com]
                                    raise ParseError.new("Syntax error.") if grpnest<0

                                    body << @scanner.scan_any(true)
                            end
                            @scanner.scan_command
                            raise ParseError.new("Environment mismatched.", @scanner.matched) unless en==(@scanner.scan_block ? @scanner[1] : @scanner.scan_any)
                            begin
                                    return parse_into(@macro.expand_environment(en, body, params, option), Array.new)
                            rescue CircularReferenceEnvironment
                                    if @expanded_environment.size>1
                                            raise
                                    else
                                            @scanner.pos = begin_pos
                                            raise ParseError.new("Circular reference.")
                                    end
                            rescue ParseError => e
                                    if @expanded_environment.size>1
                                            raise
                                    else
                                            @scanner.pos = begin_pos
                                            raise ParseError.new(%Q[Error in macro(#{e.message} "#{e.rest.strip}").])
                                    end
                            end
                    ensure
                            @expanded_environment.pop
                    end
            end

            raise ParseError.new("Undefined environment.") unless @environments.has_key?(en)
            e = @environments[en]
            e = en unless e # default method name
            __send__("env_#{e.to_s}")
    end

grp_left_etc() click to toggle source

    # File lib/math_ml/latex.rb, line 912
    def grp_left_etc
            right =
                    case @scanner[1]
                    when "left"
                            "right"
                    when "bigg"
                            "bigg"
                    end

            f = Fenced.new
            p = @scanner.pos
            o = @scanner.scan_any
            raise ParseError.new('Need brace here.') unless o && (o=~RE::BRACES || @delimiters.include?(o[RE::COMMANDS, 1]))
            f.open = (o=~RE::BRACES ? o : parse_symbol_command(o[RE::COMMANDS, 1], true))
            f << push_container(Row.new) do |r|
                    until @scanner.peek_command==right
                            if @scanner.eos?
                                    @scanner.pos = p
                                    raise ParseError.new('Brace not closed.')
                            end
                            r << parse_to_element(true)
                    end
            end
            @scanner.scan_command # skip right
            c = @scanner.scan_any
            raise ParseError.new('Need brace here.') unless c=~RE::BRACES || @delimiters.include?(c[RE::COMMANDS, 1])
            f.close = (c=~RE::BRACES ? c : parse_symbol_command(c[RE::COMMANDS, 1], true))
            f
    end