Class: MathML::LaTeX::Parser
- Inherits:
-
Object
- Object
- MathML::LaTeX::Parser
- Includes:
- MathML::LaTeX, BuiltinCommands, BuiltinEnvironments, BuiltinGroups
- Defined in:
- lib/math_ml/latex.rb
Defined Under Namespace
Classes: CircularReferenceCommand
Constant Summary collapse
- BUILTIN_MACRO =
<<'EOS' \newenvironment{smallmatrix}{\begin{matrix}}{\end{matrix}} \newenvironment{pmatrix}{\left(\begin{matrix}}{\end{matrix}\right)} \newenvironment{bmatrix}{\left[\begin{matrix}}{\end{matrix}\right]} \newenvironment{Bmatrix}{\left\{\begin{matrix}}{\end{matrix}\right\}} \newenvironment{vmatrix}{\left|\begin{matrix}}{\end{matrix}\right|} \newenvironment{Vmatrix}{\left\|\begin{matrix}}{\end{matrix}\right\|} EOS
Constants included from BuiltinCommands
BuiltinCommands::OVERS, BuiltinCommands::UNDERS
Constants included from MathML::LaTeX
Instance Attribute Summary collapse
-
#macro ⇒ Object
readonly
Returns the value of attribute macro.
-
#symbol_table ⇒ Object
readonly
Returns the value of attribute symbol_table.
-
#unsecure_entity ⇒ Object
Returns the value of attribute unsecure_entity.
Instance Method Summary collapse
- #add_commands(*a) ⇒ Object
- #add_delimiter(list) ⇒ Object
- #add_entity(list) ⇒ Object
- #add_group(begin_name, end_name, method = nil) ⇒ Object
- #add_multi_command(m, *a) ⇒ Object
- #add_plugin(plugin) ⇒ Object
- #add_sym_cmd(hash) ⇒ Object
-
#initialize(opt = {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse(src, displaystyle = false) ⇒ Object
- #push_container(container, scanner = @scanner, font = @font) ⇒ Object
Methods included from BuiltinCommands
#cmd_backslash, #cmd_entity, #cmd_frac, #cmd_hat_etc, #cmd_it_etc, #cmd_mathit_etc, #cmd_mbox, #cmd_quad_etc, #cmd_sqrt, #cmd_stackrel, #cmd_underbrace_etc
Methods included from BuiltinGroups
#add_environment, #grp_begin, #grp_left_etc
Methods included from BuiltinEnvironments
#env_array, #env_array_row, #env_matrix, #env_matrix_row
Constructor Details
#initialize(opt = {}) ⇒ Parser
Returns a new instance of Parser.
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/math_ml/latex.rb', line 365 def initialize(opt={}) @unsecure_entity = false @entities = Hash.new @commands = Hash.new @symbols = Hash.new @delimiters = Array.new @group_begins = Hash.new @group_ends = Hash.new @macro = Macro.new @macro.parse(BUILTIN_MACRO) @expanded_command = Array.new @expanded_environment = Array.new @symbol_table = opt[:symbol] || MathML::Symbol::Default @symbol_table = MathML::Symbol::MAP[@symbol_table] if @symbol_table.is_a?(::Symbol) super() end |
Instance Attribute Details
#macro ⇒ Object (readonly)
Returns the value of attribute macro.
362 363 364 |
# File 'lib/math_ml/latex.rb', line 362 def macro @macro end |
#symbol_table ⇒ Object (readonly)
Returns the value of attribute symbol_table.
363 364 365 |
# File 'lib/math_ml/latex.rb', line 363 def symbol_table @symbol_table end |
#unsecure_entity ⇒ Object
Returns the value of attribute unsecure_entity.
361 362 363 |
# File 'lib/math_ml/latex.rb', line 361 def unsecure_entity @unsecure_entity end |
Instance Method Details
#add_commands(*a) ⇒ Object
414 415 416 417 418 419 420 |
# File 'lib/math_ml/latex.rb', line 414 def add_commands(*a) if a.size==1 && Hash===a[0] @commands.merge!(a[0]) else a.each{|i| @commands[i] = false} end end |
#add_delimiter(list) ⇒ Object
430 431 432 |
# File 'lib/math_ml/latex.rb', line 430 def add_delimiter(list) @delimiters.concat(list) end |
#add_entity(list) ⇒ Object
383 384 385 386 387 |
# File 'lib/math_ml/latex.rb', line 383 def add_entity(list) list.each do |i| @entities[i] = true end end |
#add_group(begin_name, end_name, method = nil) ⇒ Object
434 435 436 437 |
# File 'lib/math_ml/latex.rb', line 434 def add_group(begin_name, end_name, method=nil) @group_begins[begin_name] = method @group_ends[end_name] = begin_name end |
#add_multi_command(m, *a) ⇒ Object
422 423 424 |
# File 'lib/math_ml/latex.rb', line 422 def add_multi_command(m, *a) a.each{|i| @commands[i] = m} end |
#add_plugin(plugin) ⇒ Object
410 411 412 |
# File 'lib/math_ml/latex.rb', line 410 def add_plugin(plugin) self.extend(plugin) end |
#add_sym_cmd(hash) ⇒ Object
426 427 428 |
# File 'lib/math_ml/latex.rb', line 426 def add_sym_cmd(hash) @symbols.merge!(hash) end |
#parse(src, displaystyle = false) ⇒ Object
389 390 391 392 393 394 395 396 397 |
# File 'lib/math_ml/latex.rb', line 389 def parse(src, displaystyle=false) @ds = displaystyle begin parse_into(src, Math.new(@ds), Font::NORMAL) rescue ParseError => e e.done = src[0...(src.size - e.rest.size)] raise end end |
#push_container(container, scanner = @scanner, font = @font) ⇒ Object
399 400 401 402 403 404 405 406 407 408 |
# File 'lib/math_ml/latex.rb', line 399 def push_container(container, scanner=@scanner, font=@font) data = [@container, @scanner, @font] @container, @scanner, @font = [container, scanner, font] begin yield container container ensure @container, @scanner, @font = data end end |