# module MathML::LaTeX::BuiltinEnvironments

### Public Class Methods

new() click to toggle source
Calls superclass method

        # File lib/math_ml/latex.rb
    967 def initialize
    968   add_environment('array', 'matrix')
    969
    970   super
    971 end

### Public Instance Methods

env_array() click to toggle source

         # File lib/math_ml/latex.rb
     973 def env_array
     974   layout = @scanner.scan_block ? @scanner.matched : @scanner.scan(/./)
     975   l = Scanner.new(layout =~ RE::BLOCK ? layout[RE::BLOCK, 1] : layout)
     976   t = Table.new
     977   aligns = []
     978   vlines = []
     979   vlined = l.check(/\|/)
     980   columned = false
     981   until l.eos?
     982     c = l.scan_any
     983     unless c =~ /[clr|@]/
     984       raise ParseError.new(
     985         'Syntax error.',
     986         layout[/\A.*(#{Regexp.escape(c + l.rest)}.*\z)/m, 1]
     987       )
     988     end
     989
     990     if c == '|'
     991       aligns << Align::CENTER if vlined
     992       vlines << Line::SOLID
     993       vlined = true
     994       columned = false
     995     else
     996       vlines << Line::NONE if columned
     997       vlined = false
     998       columned = true
     999       case c
    1000       when 'l'
    1001         aligns << Align::LEFT
    1002       when 'c'
    1003         aligns << Align::CENTER
    1004       when 'r'
    1005         aligns << Align::RIGHT
    1006       when '@'
    1007         aligns << Align::CENTER
    1008         l.scan_any
    1009       end
    1010     end
    1011   end
    1012   t.aligns = aligns
    1013   t.vlines = vlines
    1014
    1015   layout = layout[RE::BLOCK, 1] if layout =~ RE::BLOCK
    1016   raise ParseError, 'Need parameter here.' if layout == ''
    1017
    1018   hlines = []
    1019   row_parsed = false
    1020   hlined = false
    1021   until @scanner.peek_command == 'end'
    1022     raise ParseError, 'Matching \end not exist.' if @scanner.eos?
    1023
    1024     if @scanner.peek_command == 'hline'
    1025       @scanner.scan_command
    1026       t << Tr.new unless row_parsed
    1027       hlines << Line::SOLID
    1028       row_parsed = false
    1029       hlined = true
    1030     else
    1031       hlines << Line::NONE if row_parsed
    1032       t << env_array_row(l.string)
    1033       @scanner.scan(RE::WBSLASH)
    1034       row_parsed = true
    1035       hlined = false
    1036     end
    1037   end
    1038   t.hlines = hlines
    1039
    1040   if hlined
    1041     tr = Tr.new
    1042     (0..vlines.size).each { |_i| tr << Td.new }
    1043     t << tr
    1044   end
    1045
    1046   @scanner.scan_command
    1047   raise ParseError, 'Environment mismatched.' unless @scanner.check_block && @scanner[1] == 'array'
    1048
    1049   @scanner.scan_block
    1050   t
    1051 end

env_array_row(layout) click to toggle source

         # File lib/math_ml/latex.rb
    1053 def env_array_row(layout)
    1054   l = Scanner.new(layout)
    1055   r = Tr.new
    1056   first_column = true
    1057   vlined = l.check(/\|/)
    1058   until l.eos?
    1059     c = l.scan(/./)
    1060     if c == '|'
    1061       r << Td.new if vlined
    1062       vlined = true
    1063       next
    1064     else
    1065       vlined = false
    1066       case c
    1067       when 'r', 'l', 'c'
    1068       when '@'
    1069         r << parse_into(l.scan_any, Td.new)
    1070         next
    1071       end
    1072       if first_column
    1073         first_column = false
    1074       else
    1075         raise ParseError.new('Need more column.', @scanner.matched.to_s) unless @scanner.scan(/&/)
    1076       end
    1077       r << push_container(Td.new) do |td|
    1078         td << parse_to_element(true) until @scanner.peek_command == 'end' ||
    1079                                            @scanner.check(/(&|\\\\)/) || @scanner.eos?
    1080       end
    1081     end
    1082   end
    1083   r << Td.new if vlined
    1084   raise ParseError, 'Too many column.' if @scanner.check(/&/)
    1085
    1086   r
    1087 end

env_matrix() click to toggle source

         # File lib/math_ml/latex.rb
    1089 def env_matrix
    1090   t = Table.new
    1091   hlines = []
    1092   hlined = false
    1093   row_parsed = false
    1094   until @scanner.peek_command == 'end'
    1095     raise ParseError, 'Matching \end not exist.' if @scanner.eos?
    1096
    1097     if @scanner.peek_command == 'hline'
    1098       @scanner.scan_command
    1099       t << Tr.new unless row_parsed
    1100       hlines << Line::SOLID
    1101       row_parsed = false
    1102       hlined = true
    1103     else
    1104       hlines << Line::NONE if row_parsed
    1105       t << (r = Tr.new)
    1106       r << (td = Td.new)
    1107       until @scanner.check(RE::WBSLASH) || @scanner.peek_command == 'end' || @scanner.eos?
    1108         push_container(td) do |e|
    1109           e << parse_to_element(true) until @scanner.peek_command == 'end' ||
    1110                                             @scanner.check(/(&|\\\\)/) || @scanner.eos?
    1111         end
    1112         r << (td = Td.new) if @scanner.scan(/&/)
    1113       end
    1114       @scanner.scan(RE::WBSLASH)
    1115       row_parsed = true
    1116       hlined = false
    1117     end
    1118   end
    1119   t.hlines = hlines
    1120
    1121   t << Tr.new if hlined
    1122
    1123   raise ParseError, 'Need \\end{array}.' unless @scanner.peek_command == 'end'
    1124
    1125   @scanner.scan_command
    1126   raise ParseError, 'Environment mismatched.' unless @scanner.check_block && @scanner[1] == 'matrix'
    1127
    1128   @scanner.scan_block
    1129   t
    1130 end

env_matrix_row() click to toggle source

         # File lib/math_ml/latex.rb
    1132 def env_matrix_row
    1133   r = Tr.new
    1134   until @scanner.check(RE::WBSLASH) || @scanner.peek_command == 'end'
    1135     r << push_container(Td.new) do |td|
    1136       td << parse_to_element(true) until @scanner.peek_command == 'end' ||
    1137                                          @scanner.check(/(&|\\\\)/) || @scanner.eos?
    1138     end
    1139   end
    1140 end