# module MathML::LaTeX::BuiltinGroups

### Public Class Methods

new() click to toggle source
Calls superclass method

        # File lib/math_ml/latex.rb
    846 def initialize
    847   add_group('begin', 'end')
    848   add_group('left', 'right', :left_etc)
    849   add_group('bigg', 'bigg', :left_etc)
    850   @environments = {}
    851
    852   super
    853 end

### Public Instance Methods

add_environment(*a) click to toggle source

        # File lib/math_ml/latex.rb
    855 def add_environment(*a)
    856   @environments ||= {}
    857   if a.size == 1 && a[0].is_a?(Hash)
    858     @environments.merge!(hash)
    859   else
    860     a.each { |i| @environments[i] = false }
    861   end
    862 end

grp_begin() click to toggle source

        # File lib/math_ml/latex.rb
    864 def grp_begin
    865   matched = @scanner.matched
    866   begin_pos = @scanner.pos - matched.size
    867   en = @scanner.scan_block ? @scanner[1] : @scanner.scan_any
    868   raise ParseError, 'Environment name not exist.' unless en
    869
    870   macro = @macro.environments(en)
    871   if macro
    872     begin
    873       flg = @expanded_environment.include?(en)
    874       @expanded_environment.push(en)
    875       raise CircularReferenceEnvironment if flg
    876
    877       pos = @scanner.pos
    878       option = macro.option && @scanner.scan_option ? @scanner[1] : nil
    879       params = []
    880       (1..macro.num).each do
    881         params << (@scanner.scan_block ? @scanner[1] : @scanner.scan_any)
    882         raise ParseError, 'Need more parameter.' unless params.last
    883       end
    884       body = ''
    885       grpnest = 0
    886       until @scanner.peek_command == 'end' && grpnest == 0
    887         if @scanner.eos?
    888           @scanner.pos = pos
    889           raise ParseError, 'Matching \end not exist.'
    890         end
    891         com = @scanner.peek_command
    892         grpnest += 1 if @group_begins.has_key?(com)
    893         grpnest -= 1 if @group_ends.has_key?(com) && @group_begins[com]
    894         raise ParseError, 'Syntax error.' if grpnest < 0
    895
    896         body << @scanner.scan_any(true)
    897       end
    898       @scanner.scan_command
    899       unless en == (@scanner.scan_block ? @scanner[1] : @scanner.scan_any)
    900         raise ParseError.new('Environment mismatched.',
    901                              @scanner.matched)
    902       end
    903
    904       begin
    905         return parse_into(@macro.expand_environment(en, body, params, option), [])
    906       rescue CircularReferenceEnvironment
    907         if @expanded_environment.size > 1
    908           raise
    909         else
    910           @scanner.pos = begin_pos
    911           raise ParseError, 'Circular reference.'
    912         end
    913       rescue ParseError => e
    914         if @expanded_environment.size > 1
    915           raise
    916         else
    917           @scanner.pos = begin_pos
    918           raise ParseError, %[Error in macro(#{e.message} "#{e.rest.strip}").]
    919         end
    920       end
    921     ensure
    922       @expanded_environment.pop
    923     end
    924   end
    925
    926   raise ParseError, 'Undefined environment.' unless @environments.has_key?(en)
    927
    928   e = @environments[en]
    929   e ||= en # default method name
    930   __send__("env_#{e}")
    931 end

grp_left_etc() click to toggle source

        # File lib/math_ml/latex.rb
    933 def grp_left_etc
    934   right =
    935     case @scanner[1]
    936     when 'left'
    937       'right'
    938     when 'bigg'
    939       'bigg'
    940     end
    941
    942   f = Fenced.new
    943   p = @scanner.pos
    944   o = @scanner.scan_any
    945   raise ParseError, 'Need brace here.' unless o && (o =~ RE::BRACES || @delimiters.include?(o[RE::COMMANDS, 1]))
    946
    947   f.open = (o =~ RE::BRACES ? o : parse_symbol_command(o[RE::COMMANDS, 1], true))
    948   f << push_container(Row.new) do |r|
    949     until @scanner.peek_command == right
    950       if @scanner.eos?
    951         @scanner.pos = p
    952         raise ParseError, 'Brace not closed.'
    953       end
    954       r << parse_to_element(true)
    955     end
    956   end
    957   @scanner.scan_command # skip right
    958   c = @scanner.scan_any
    959   raise ParseError, 'Need brace here.' unless c =~ RE::BRACES || @delimiters.include?(c[RE::COMMANDS, 1])
    960
    961   f.close = (c =~ RE::BRACES ? c : parse_symbol_command(c[RE::COMMANDS, 1], true))
    962   f
    963 end