# module MathML::LaTeX::BuiltinEnvironments

### Public Class Methods

new() click to toggle source
Calls superclass method

    # File lib/math_ml/latex.rb, line 944
    def initialize
            add_environment("array", "matrix")

            super
    end

### Public Instance Methods

env_array() click to toggle source

    # File lib/math_ml/latex.rb, line 950
    def env_array
            layout = @scanner.scan_block ? @scanner.matched : @scanner.scan(/./)
            l = Scanner.new(layout=~RE::BLOCK ? layout[RE::BLOCK, 1] : layout)
            t = Table.new
            aligns = Array.new
            vlines = Array.new
            vlined = l.check(/\|/)
            columned = false
            until l.eos?
                    c = l.scan_any
                    raise ParseError.new("Syntax error.", layout[/\A.*(#{Regexp.escape(c+l.rest)}.*\z)/m, 1]) unless c=~/[clr\|@]/

                    if c=='|'
                            aligns << Align::CENTER if vlined
                            vlines << Line::SOLID
                            vlined = true
                            columned = false
                    else
                            vlines << Line::NONE if columned
                            vlined = false
                            columned = true
                            case c
                            when 'l'
                                    aligns << Align::LEFT
                            when 'c'
                                    aligns << Align::CENTER
                            when 'r'
                                    aligns << Align::RIGHT
                            when '@'
                                    aligns << Align::CENTER
                                    l.scan_any
                            end
                    end
            end
            t.aligns = aligns
            t.vlines = vlines

            layout = layout[RE::BLOCK, 1] if layout=~RE::BLOCK
            raise ParseError.new('Need parameter here.') if layout==""

            hlines = Array.new
            row_parsed = false
            hlined = false
            until @scanner.peek_command=="end"
                    raise ParseError.new('Matching \end not exist.') if @scanner.eos?
                    if @scanner.peek_command=="hline"
                            @scanner.scan_command
                            t << Tr.new unless row_parsed
                            hlines << Line::SOLID
                            row_parsed = false
                            hlined = true
                    else
                            hlines << Line::NONE if row_parsed
                            t << env_array_row(l.string)
                            @scanner.scan(RE::WBSLASH)
                            row_parsed = true
                            hlined = false
                    end
            end
            t.hlines = hlines

            if hlined
                    tr = Tr.new
                    (0..vlines.size).each {|i| tr << Td.new}
                    t << tr
            end

            @scanner.scan_command
            raise ParseError.new("Environment mismatched.") unless @scanner.check_block && @scanner[1]=="array"
            @scanner.scan_block
            t
    end

env_array_row(layout) click to toggle source

    # File lib/math_ml/latex.rb, line 1023
    def env_array_row(layout)
            l = Scanner.new(layout)
            r = Tr.new
            first_column = true
            vlined = l.check(/\|/)
            until l.eos?
                    c = l.scan(/./)
                    if c=='|'
                            r << Td.new if vlined
                            vlined = true
                            next
                    else
                            vlined = false
                            case c
                            when 'r', 'l', 'c'
                            when '@'
                                    r << parse_into(l.scan_any, Td.new)
                                    next
                            end
                            if first_column
                                    first_column = false
                            else
                                    raise ParseError.new("Need more column.", @scanner.matched.to_s) unless @scanner.scan(/&/)
                            end
                            r << push_container(Td.new) do |td|
                                    td << parse_to_element(true) until @scanner.peek_command=="end" || @scanner.check(/(&|\\\\)/) || @scanner.eos?
                            end
                    end
            end
            r << Td.new if vlined
            raise ParseError.new("Too many column.") if @scanner.check(/&/)
            r
    end

env_matrix() click to toggle source

    # File lib/math_ml/latex.rb, line 1057
    def env_matrix
            t = Table.new
            hlines = Array.new
            hlined = false
            row_parsed = false
            until @scanner.peek_command=="end"
                    raise ParseError.new('Matching \end not exist.') if @scanner.eos?
                    if @scanner.peek_command=="hline"
                            @scanner.scan_command
                            t << Tr.new unless row_parsed
                            hlines << Line::SOLID
                            row_parsed = false
                            hlined = true
                    else
                            hlines << Line::NONE if row_parsed
                            t << (r = Tr.new)
                            r << (td=Td.new)
                            until @scanner.check(RE::WBSLASH) || @scanner.peek_command=="end" || @scanner.eos?
                                    push_container(td) do |e|
                                            e << parse_to_element(true) until @scanner.peek_command=="end" || @scanner.check(/(&|\\\\)/) || @scanner.eos?
                                    end
                                    r << (td=Td.new) if @scanner.scan(/&/)
                            end
                            @scanner.scan(RE::WBSLASH)
                            row_parsed = true
                            hlined = false
                    end
            end
            t.hlines = hlines

            t << Tr.new if hlined

            raise ParseError.new("Need \\end{array}.") unless @scanner.peek_command=="end"
            @scanner.scan_command
            raise ParseError.new("Environment mismatched.") unless @scanner.check_block && @scanner[1]=="matrix"
            @scanner.scan_block
            t
    end

env_matrix_row() click to toggle source

    # File lib/math_ml/latex.rb, line 1096
    def env_matrix_row
            r = Tr.new
            until @scanner.check(RE::WBSLASH) || @scanner.peek_command=="end"
                    r << push_container(Td.new) do |td|
                            td << parse_to_element(true) until @scanner.peek_command=="end" || @scanner.check(/(&|\\\\)/) || @scanner.eos?
                    end
            end
    end