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.
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/math_ml/latex.rb', line 375 def initialize(opt = {}) @unsecure_entity = false @entities = {} @commands = {} @symbols = {} @delimiters = [] @group_begins = {} @group_ends = {} @macro = Macro.new @macro.parse(BUILTIN_MACRO) @expanded_command = [] @expanded_environment = [] @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.
373 374 375 |
# File 'lib/math_ml/latex.rb', line 373 def macro @macro end |
#symbol_table ⇒ Object (readonly)
Returns the value of attribute symbol_table.
373 374 375 |
# File 'lib/math_ml/latex.rb', line 373 def symbol_table @symbol_table end |
#unsecure_entity ⇒ Object
Returns the value of attribute unsecure_entity.
372 373 374 |
# File 'lib/math_ml/latex.rb', line 372 def unsecure_entity @unsecure_entity end |
Instance Method Details
#add_commands(*a) ⇒ Object
426 427 428 429 430 431 432 |
# File 'lib/math_ml/latex.rb', line 426 def add_commands(*a) if a.size == 1 && a[0].is_a?(Hash) @commands.merge!(a[0]) else a.each { |i| @commands[i] = false } end end |
#add_delimiter(list) ⇒ Object
442 443 444 |
# File 'lib/math_ml/latex.rb', line 442 def add_delimiter(list) @delimiters.concat(list) end |
#add_entity(list) ⇒ Object
393 394 395 396 397 |
# File 'lib/math_ml/latex.rb', line 393 def add_entity(list) list.each do |i| @entities[i] = true end end |
#add_group(begin_name, end_name, method = nil) ⇒ Object
446 447 448 449 |
# File 'lib/math_ml/latex.rb', line 446 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
434 435 436 |
# File 'lib/math_ml/latex.rb', line 434 def add_multi_command(m, *a) a.each { |i| @commands[i] = m } end |
#add_plugin(plugin) ⇒ Object
422 423 424 |
# File 'lib/math_ml/latex.rb', line 422 def add_plugin(plugin) extend(plugin) end |
#add_sym_cmd(hash) ⇒ Object
438 439 440 |
# File 'lib/math_ml/latex.rb', line 438 def add_sym_cmd(hash) @symbols.merge!(hash) end |
#parse(src, displaystyle = false) ⇒ Object
399 400 401 402 403 404 405 406 407 |
# File 'lib/math_ml/latex.rb', line 399 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
409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/math_ml/latex.rb', line 409 def push_container(container, scanner = @scanner, font = @font) data = [@container, @scanner, @font] @container = container @scanner = scanner @font = font begin yield container container ensure @container, @scanner, @font = data end end |